For loop:
while loop:
Syntax:
while(Condition/Boolean Expression) {
//do work
//increment
int i = 1;
i++;//i = i+1;
}
do while loop:
Syntax:
do {
//do work
Example:
System.out.println(i); //printing 1 to 10 on console
i++;//i = i+1;
} while(i<=10);
foreach loop:
Syntax:
Example:
}
Syntax:
for(initialization ; Condition/Boolean Expression ; increment) {
//do work
}
Example:
for(int i = 1 ; i =< 10 ; i++) {
System.out.println(i); //printing 1 to 10 on console
}
while loop:
Syntax:
while(Condition/Boolean Expression) {
//do work
//increment
}
Example:
while(i<=10) {
System.out.println(i); //printing 1 to 10 on consolei++;//i = i+1;
}
do while loop:
Syntax:
do {
//do work
} while (condition);
int i = 1;
do {System.out.println(i); //printing 1 to 10 on console
i++;//i = i+1;
} while(i<=10);
foreach loop:
Syntax:
for( initialization/declarations : expression ) {
//do work
}
String[] fruits = {"Apple","Mango","Banana"};
for(String everyfruit : fruits){
System.out.println(everyfruit); //printing fruits on console}
0 comments:
Post a Comment