Flow of control in a WHILE loop:
- When executing, if the boolean_expression in while result is true, then the actions inside the loop will be executed. This will continue as long as the expression result is true.
- Here, key point of the while loop is that the loop might not ever run. When the expression is tested and the result is false, the loop body will be skipped and the first statement after the while loop will be executed.
Example
public class HelloWorld{public static void main(String []args){
int i = 5;
int k = 0;
while(k<=i){
System.out.println(k+"\n");
k++;
}
}
}
No comments:
Post a Comment