Branching
if (i < 2)
a =3;
else if (i < 3)
a = 4;
else {
a = 5;
b = 2;
}
- The standard branching operation is the if else. Each if takes
a boolean expression. (Be careful with (a=3) in some languages
and versions).
- Programs are made up of series of statements. Assignment
is one type of statement. If is another.
- If is a statement that contains statements.
- If you want to use multiple statements where one should go, you need
a compound statement. That's what {} is for.
- You can use a switch statement to, and of course an if then else cascade.