xxxxxxxxxx
int ctr = 1;
do
{
System.out.println(ctr); // print ctr value
ctr++; // increment ctr value by 1
}while(ctr <= 10);
xxxxxxxxxx
//while loop
int i=1;
while(i<=10){
System.out.println(i);
i++;
}
xxxxxxxxxx
do {
//something you want to execute at least once
} while (someBooleanCondition);
xxxxxxxxxx
int count = 10;
while(count < 10) {
System.out.println(count);
count++;
}
//while will run when if the condition is true
//if count is less then 10 the condition is true
//if count is more then 10 or equals to 10 it is false.
xxxxxxxxxx
while(i < 5) //while i < 5 stay in the loop
{
System.out.print(i);
i++;
}
/*
do someting
change variable
call methods
etc...
*/
xxxxxxxxxx
// Starting on 0:
int i=0; // initialization
while(i<10){ // condition
System.out.println(i);
i++; // increment operation
}
// Starting on 1:
int i=1;
while(i<=10){
System.out.println(i);
i++;
}
xxxxxxxxxx
//do-while loop
int i=1;
do{
System.out.println(i);
i++;
}while(i<=10);
xxxxxxxxxx
while(booleanCondition){
// run your code here
}// while
do while loops will run once no matter what, but while loops will only run
if the boolean condition is satisfied