Page 188 - Computer science 868 Class 12
P. 188
Input:
year=2
marks=80
Output:
Second-year student
You are eligible for the certificate
Difference between if-else and switch case
if-else switch case
The flow of control is bidirectional. The flow of control is multidirectional,
i.e., depending on the choice of the user.
All kinds of relational operators are used in The condition is satisfied if the choice
the condition. variable matches the case value.
Any data type can be used in the condition Only int and char data types and string
expression. are used in the switch expression.
Satisfied condition returns true else Satisfied condition neither returns true
returns false. nor false.
7.3 ITERATIVE STATEMENTS
Sometimes, the logic of a program requires to repeating certain lines of program code to get the desired answer. This
repetitive code is called a repetitive or iterative statement. The iterative statements form a loop and execute for zero
or more times to get the desired result. The execution will stop when criteria in the condition given in for loop does
not match. Though there is another way to terminate from the loop by using jump statements.
Different parts of a loop are:
• Starting value/Initialisation
• Test condition
• Increment or decrement, also known as step value
• Body of the loop
There are three types of loops. Let us see this in detail.
7.3.1 for Loop
Java ‘for’ loop executes a set of statements repeatedly for a fixed number of times. As soon as the control statement
does not match the condition, the loop terminates. It is known as an entry-controlled loop because the condition is
checked in the beginning or before executing the body of the for loop.
The syntax of for loop is:
for(initialisation; condition for testing; increment or decrement)
{
// job performed by the body of the loop
}
For example:
a. for(i=5; i<=20; i=i+5)
System.out.println(i);
The above example prints all the multiples of 5 up to 20.
186186 Touchpad Computer Science-XII

