Java – while and do-while loops

while

A loop that can run indefinitely until it meets a conditions. Use while loop when number of repetitions is unknown.

syntax:

while(test){
statements;
}

example:

while and do while loops, <span>Java – while and do-while loops</span>, KandZ
while and do while loops, <span>Java – while and do-while loops</span>, KandZ

do-while

It is almost the same as while. Use it when you know that you need to execute the loop at least once

syntax:

do{
statements;
} while(test);

example:

int count=0;  //initialize
do
{
System.out.println(count);
count++; //increment
} while (count<10); //test
while and do while loops, <span>Java – while and do-while loops</span>, KandZ

THE END!!!

86810cookie-checkJava – while and do-while loopsJava – while and do-while loops

Related posts

3 Thoughts to “Java – while and do-while loops

  1. […] Java – while and do-while loops […]

  2. […] Java – while and do-while loops […]

  3. […] Java – while and do-while loops […]

Comments are closed.