xxxxxxxxxx
do {
//something you want to execute at least once
} while (someBooleanCondition);
xxxxxxxxxx
//while loop
int i=1;
while(i<=10){
System.out.println(i);
i++;
}
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
// 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
int ctr = 1;
do
{
System.out.println(ctr); // print ctr value
ctr++; // increment ctr value by 1
}while(ctr <= 10);
xxxxxxxxxx
public static void main(String[] args) {
int myNumber = 1;
while(myNumber != 1000) {
if((myNumber % 2) != 0) {
myNumber++; }
else {
System.out.println(myNumber + " is even");
myNumber++;
}
}
}
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