If-else statement

The if else statement has a statement or code black that is executed when the conditional expression is true, and an else clause may be used to indicate a statement of code block that is executed when the conditional expression evaluates to false.

if-else statements can be chained together, with the start of the next if statement as the body of the previous else clause:

if (a == 1) 
   print("a is one");
else if (a == 2)
   print("a is two");
else
   print("a is neither one or two");

If statements can be nested (as with all statement types). It is best to use code blocks and clean indentation for this purpose to make the intent absolutely clear.

if (a == 1) {
   if (b == 1)
      print("a and b are one");
   else
      print("a is one but b is not");
} else
    print("a is not one, did not check b");