This book is now obsolete Please use CSAwesome instead.

5.2. Three or More Options

You can even pick between 3 or more possibilites. Just add else if for each possibility after the first if and before the last possibility, the else.


Figure 1: The order that statements execute in a conditional with 3 options: if, else if, and else

Run the code below and try changing the value of x to get each of the three possible lines in the conditional to print.


Another way to handle 3 or more conditional cases is to use the switch and break keywords, but these will not be on the exam. For a tutorial on using switch see

Check your understanding

You have attempted of activities on this page