Loop control structure in java.■ for loop.■ while loop.■ do-while loop.
■》Loops->
A loop is used for executing a block of statements repeatedly until a particular condition is satisfied. A loop consists of an initialization statement, a test condition and an increment/decrement statement.
1● For Loop->
The syntax of the for loop is ->
for (initialization; condition; update) {
// body of-loop
}
■》Example->
for (int i=1; i<=20; i++) {
System.out.println(i);
}
2● While Loop->
The syntax for while loop is :
initialization;
while(condition) {
// body of the loop
update;
}
■》Example->
int i = 0;
while(i<=20) {
System.out.println(i);
i++;
}
3● Do-While Loop->
The syntax for the do-while loop is :
initialization;
do {
// body of loop;
update;
}
while (condition);
■》Example->
int i = 0;
do {
System.out.println(i);
i++;
} while(i<=20);
Comments
Post a Comment