Page 82 - iprime_V2.2_class8
P. 82
break;
case 5:
System.out.println("Today is Friday");
break;
case 6:
System.out.println("Today is Saturday");
break;
case 7:
System.out.println("Today is Sunday");
break;
default:
System.out.println("Invalid day number");
}
}
}
After compiling the preceding program, run it twice and
enter values 6 and 8. When you enter value 6, case 6 will
be executed and the output “Today is Saturday” will be
displayed on the terminal.
Output When Input Is 6
When you enter value 8, none of the cases will be
matched. Hence, the default case will be executed and
the output “Invalid day number” will be displayed on the
terminal.
Output When Input Is 8
LOOP STATEMENTS
Loop statements are control flow statements that allow us to repeatedly execute a set of
statements for a given number of times. These are also called iteration statements or loops.
Java provides three kinds of loop statements:
while
do-while
for
The 'for' loop is more commonly used as compared to 'while' and 'do-while' loops.
Let us learn about these in detail.
80 iPRIME (Ver. 2.2)–VIII

