The if-then Statement
The if-then Statement
void applyBrakes() {
// the "if" clause: bicycle must be moving
if (isMoving){
// the "then" clause: decrease current speed
currentSpeed--;
}
}
It tells your program to execute a certain section of code only if a particular test evaluates to true. If this test evaluates to false, control jumps to the end of the if-then statement.
The opening and closing braces are optional, provided that the "then" clause contains only one statement.
Related concepts
→
The if-then Statement
→