[go: up one dir, main page]

0% found this document useful (0 votes)
24 views20 pages

Java Loop

The document discusses loops in Java including the for, while, and do-while loops. It provides the syntax for each loop type and examples of each. The for loop runs a block of code for a specified number of iterations using an initialization, condition, and increment/decrement. The while loop runs a block of code while a condition is true. The do-while loop runs a block of code once and then continues to run the block as long as the condition is true.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
24 views20 pages

Java Loop

The document discusses loops in Java including the for, while, and do-while loops. It provides the syntax for each loop type and examples of each. The for loop runs a block of code for a specified number of iterations using an initialization, condition, and increment/decrement. The while loop runs a block of code while a condition is true. The do-while loop runs a block of code once and then continues to run the block as long as the condition is true.
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 20

LOOP Statement

Java
Three basic loops:

• for
• while
• do-while
Syntax of for loop:

for(initialization; condition ; increment/decrement)


{
statement(s);
}
Example of Simple for loop
class ForLoopExample
{
public static void main(String args[]){
for(int i=10; i>1; i--)
{
System.out.println("The value of i is: "+i);
}
}}
The output of this program is:
The value of i is: 10
The value of i is: 9
The value of i is: 8
The value of i is: 7
The value of i is: 6
The value of i is: 5
The value of i is: 4
The value of i is: 3
The value of i is: 2
Syntax of while loop

while(condition)
{
statement(s);
}
Simple while loop example
class WhileLoopExample {
public static void main(String args[]){
int i=10;
while(i>1)
{
System.out.println(i);
i--;
}
}}
The output of this program is:
10
9
8
7
6
5
4
3
2
Syntax of do-while loop:
do
{
statement(s);
}
while(condition);
do-while loop example
class DoWhileLoopExample {
public static void main(String args[]){
int i=10;
do {
System.out.println(i); i--;
}
while(i>1);
}
}
Output:
10
9
8
7
6
5
4
3
2
Title and Content Layout with Chart
Two Content Layout with Table
• First bullet point here
Group 1 Group 2
• Second bullet point here
Class 1 82 95
• Third bullet point here
Class 2 76 88

Class 3 84 90
Two Content Layout with SmartArt
• First bullet point here

• Second bullet point here Task


• Third bullet point here
1

Group
A
Task Task
3 2

You might also like