Page 85 - TP_iPlus_V2.1_Class8
P. 85
System.out.println("The value
of i is: " + i);
i++;
}
while (i <= 10);
}
}
If we change the condition used in the preceding program
from (i <= 10) to (i >= 10), the do-while loop executes the
statements only once and stops executing. However, the
condition is false. The output will be displayed as shown:
Output
The for Loop Start
The for loop in Java helps to repeat a
Initialisation
set of statements a definite number of
times. It is designed to process the items
of any sequence one by one.
False
The syntax of the for loop is as follows: Conditional
Expression
for (initialisation;
conditional expression; Increment/Decrement
True
increment/decrement)
Body of for loop
{
[statements]
Stop
}
Flowchart of the for loop
Where, the initialisation section initialises a variable when the loop starts its execution. This
section executes only once and controls the execution of the for loop. The semicolon symbol will
terminate the initialisation section. Next, the conditional expression section will be evaluated.
This section contains a test condition. The body of the loop will be executed until the test
condition becomes false. At the end, the increment/decrement section will be executed. It
controls the iterations of the for loop.
For example:
public class ForLoop
{
public static void main(String args[])
{
int i;
for(i=1; i<=10; i++)
{
83
Conditional, Looping and Jump Statements in Java

