This tutorial, helps you to understand the concept of while loop in java 7.
While Loop Statements :
While loop is most used loop in programming. We put the condition with in the while loop and if condition satisfied then the while block executes otherwise break the loop. You can use any counter to iterate the loop. This type of control structure repeat the task certain number of times. It is more easier to understand in comparison to for loops.
Syntax :
while(boolean_expression){
//statement
}
When executing, if the expression result is true then statement inside the loop will get executed and it will continue as long as the expression result is true.
Example :
Here is Simple example of while loop.
package looping;
class WhileLoop {
public static void main(String[] args) {
int i = 1;
System.out.println("While loop example");
// Using while loop
while (i <= 10) {
System.out.println("Hello " + i);
i++; // incrementing i with 1
}
}
}
Output :
While loop example... Hello 1 Hello 2 Hello 3 Hello 4 Hello 5 Hello 6 Hello 7 Hello 8 Hello 9 Hello 10
If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.
Ask your questions, our development team will try to give answers to your questions.
Ask Questions? Discuss: While Loop Statement in java 7
Post your Comment