While Loop Example Java Program
Definition
A while loop is a control flow statement that allows code to be executed repeatedly based on a given boolean condition. The while loop can be thought of as a repeating if statement. The while construct consists of a block of code and a condition/expression.Syntax
while(Condition){
//DO something
}While Loop Example Program
class WhileLoopExample{
public static void main(String[] args){
int num=0;
while(num<=5){
System.out.println(""+num);
num++;
}
}
}
Sample Output
Output is: 0 1 2 3 4 5
Read More Articles
- Multiple Inheritance Using Interface Example Java Program
- Single Inheritance Example Java Program
- Multilevel Inheritance Example Java Program
- Hierarchical Inheritance Example Java Program
- Create Matrix Example Java Program
- Find all Substrings of a given string Example Java Program
- Sum Of Three Numbers Example Java Program
- Twin Prime Example Java Program
- Heap Sort Example Java Program
- Compile Time Polymorphism Example Java Program
