Java while
What is Loops?
When we want to execute a block execute multiple time then we use loop.It executes until condition is true.
The while
executes a block of code as long as a given condition is true.
while (condition) {
// code block to be executed
}
Sample program with if
Write a program or WAP to print 1 to 10 using while loop.
class SampleSwitch
{
public static void main(String args[])
{
int num= 1;
while (num <= 10) {
System.out.println(num);
num++;
}
}
}
Output:
1 2 3 4 5 6 7 8 9 10java java tutorials learn java study java