Lab5-If
Control Statements:
(1.) 'Selection': if and nested if (2.) 'Loops': while, for and do.
This lab will go over how to use if and nested if
in your application.
if (pg. 128):
if (condition1){
…statement that does something;
}else{
…statement that does something else;
}
Multibranch Selection:
if (condition1){
… do something;
}else if(condition2){
… do this instead;
}
Nested if (pg. 129):
if (condition1){
if (condition 2){
… do something;
else
... do something;
}
}
else {
… do this instead;
}
- Condition:
- Has to be a boolean expression that evaluates to
true
orfalse
.If the condition is true the statement (or the body of if) is executed otherwise skipped.