while loop
The java while loop used to iterate a part of the program several times. If the number of iteration is not fixed,it recommended to use while loop.
Syntax:
while(condition){
//code to be executed
}
fig: While loop
Example:
public class WhileExample {
public static void main(String[] args) {
int i=1;
while(i<=10){
System.out.println(i);
i++;
}
}
}
Output:1
2
3
4
5
6
7
8
9
10
No comments:
Post a Comment