User Tools

Site Tools


programming:if_switch

If Statements

If statements are used If you have a condition you need to meet.

//if statement syntax
if(condition)
{
    //run this code here
}
//ex. simple if statement.
if(x < num ){
  Console.log(x);  //this logs the number x to Console
  x++;   //this adds 1 to number x
}

Switch Statements

//Switch statement syntax
switch(case#)
{
       case 1: //this = if 1
             //code here
             break;
       //can put more cases in and have as many as you want      
       default: //default is used if and only if you input a case# that is not on your case list 
             //code here
             break;
//ex.
switch(num)
{
	case 5:
		num = 1;
		break;
	default:
		num = 0;
		break;
}

Back to the C# page

programming/if_switch.txt · Last modified: 2018/10/24 22:57 by kvederism