Use of the if-then statement, the most basic form of program flow control, should include
void distributeCandy() {
// the "if" clause: must have candy
if (isCandy)
{
// the "then" clause: distribute candy to students
numberCandy--;
}
}
If this test evaluates to false (there is no candy), control jumps to the end of the if-then statement. The use of the if-then-else statement includes: The if-then-else statement
void distributeCandy() {
// the "if" clause: must have candy
if (isCandy)
{
// the "then" clause: distribute candy to students
numberCandy--;
} else
{
System.err.println("The candy jar is empty");
}
}