Coding Basics: Conditionals

Example 1:

x = 5;

if (x >3) x = x + 2;

//x holds the value 7


Example 2:

y = 3;

if (y==4) y = y + 3;

else y = y - 1;

//y holds the value 2 because the condition in the if statement is not true


Example 3:

a = 2;

b = 3;

c = 0;

if (a+b < 4) c++;

else if (a + b < 6) c = c + 4;

else c = c + 5;

//c holds the value 4.  The condition in the if statement is false, but the condition in the else if statement is true.