//while loop
int i=1;
while(i<=10){
System.out.println(i);
i++;
}
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.
for (let i = 1; i <=5; ++i) {
// body of loop
}
do {
// code block to be executed
}
while (condition);
do {
// body of loop
} while(textExpression);
do {
//something you want to execute at least once
} while (someBooleanCondition);
while(i < 5) //while i < 5 stay in the loop
{
System.out.print(i);
i++;
}
/*
do someting
change variable
call methods
etc...
*/
do
{
// do something
} while (true);
//do-while loop
int i=1;
do{
System.out.println(i);
i++;
}while(i<=10);
int ctr = 1;
do
{
System.out.println(ctr); // print ctr value
ctr++; // increment ctr value by 1
}while(ctr <= 10);
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
while (testExpression) {
// body of loop
}
int number = 1;
while(number < 10){
System.out.println(number);
number += 1;
}
int count = 1;while (count < 11) { System.out.println("The count is " + count); count++; // remember, this increases the value of count by 1}
while(condition) {
}
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++;
}
}
}