IF and IF Else

If statement is used to declare and obeyed the single conditions while wlse if for multiple conditions of the program just like an electric button functions (ON / OFF)

Syntax (Single Condition) :
int a;
string b = "true";
a = 10 / 5; if (a == 2) 
 MessageBox.Show(b);
}

Result:
Display "True" on messagebox or dialog box.

Syntax (Multiple Conditions) :
int a;
string b = "true";
string c = "wow";
a = 5 / 5;
if (a == 2)
{
   MessageBox.Show(b);
}
else if (a == 1)
{
   MessageBox.Show(c);
}

Result:
Display "wow" on messagebox or dialob box.

No comments:

Post a Comment