Computer Languages
Elements - If .... Then .... Else (1 of 2)


If...Then...Else statements allow decisions to be made in a program. This includes deciding which statements are to be executed. In the example below the variables 'aboveNinety' and 'belowNinety' are first set to the value zero. The value 1 is added to 'aboveNinety' or 'belowNinety' for each 'Score' that is over or below 90 using the If ... Then ... Else statement. The results are then printed to the screen.

e.g.
aboveNinety := 0;
belowNinety := 0;
IF (Score > 90) THEN

aboveNinety := aboveNinety + 1;
ELSE
belowNinety := belowNinety +1;
print aboveNinety , "Language(s) above 90%";
print belowNinety , "Language(s) below 90%";