do while loop example
Example 1: do whie loop
do{
----
} while(condition);
Example 2: do statement java
do
{
statement(s);
} while(condition);
Example 3: while loop vs do while
Main difference while loop executes while
condition is true. But do while executes
at least one time regardless.
Example 4: do statement java
10
9
8
7
6
5
4
3
2
Example 5: do statement java
class DoWhileLoopExample2 {
public static void main(String args[]){
int arr[]={2,11,45,9};
//i starts with 0 as array index starts with 0
int i=0;
do{
System.out.println(arr[i]);
i++;
}while(i<4);
}
}
Example 6: while loop
var i=1;
while(i<=10){
document.write(i + "
");
i++;}