Search
 
SCRIPT & CODE EXAMPLE
 

JAVA

Do..While Loop

A do...while loop is similar to a while loop, except that a do...while loop is guaranteed to execute at least one time. 

Syntax : 
do {
   // Statements
}while(Boolean_expression);
Notice that the Boolean expression appears at the end of the loop, so the statements in the loop execute once before the Boolean is tested.

If the Boolean expression is true, the control jumps back up to do statement, and the statements in the loop execute again. This process repeats until the Boolean expression is false.
Comment

Example of a Do..While Loop

public class Test {

   public static void main(String args[]) {
      int x = 10;

      do {
         System.out.print("value of x : " + x );
         x++;
         System.out.print("
");
      }while( x < 20 );
   }
}
Comment

Example of While Loop

public class Test {

   public static void main(String args[]) {
      int x = 10;

      while( x < 20 ) {
         System.out.print("value of x : " + x );
         x++;
         System.out.print("
");
      }
   }
}
Comment

do while loop

let i = true;
do{
	i= true; or // i = false;
}while(i == true);
Comment

what are while loops

# There are 2 types of loops in python
# while loops and for loops
# a while loops continues for an indefinite amount of time
# until a condition is met:

x = 0
y = 3
while x < y:
    print(x)
    x = x + 1

>>> 0
>>> 1
>>> 2

# The number of iterations (loops) that the while loop above
# performs is dependent on the value of y and can therefore change

######################################################################

# below is the equivalent for loop:
for i in range(0, 3):
    print(i)

>>> 0
>>> 1
>>> 2

# The for loop above is a definite loop which means that it will always
# loop three times (because of the range I have set)
# notice that the loop begins at 0 and goes up to one less than 3.
Comment

do while loop

<?php
	$num=1;
	do{
		$num++;
		echo"The number is ".$num."<br>";
	}
	while($num<=5);
	
//======output=====
/*
The number is 2
The number is 3
The number is 4
The number is 5
The number is 6
*/

?>
Comment

PREVIOUS NEXT
Code Example
Java :: how to use java 
Java :: navigation bottom android 
Java :: android how to know when snackbar is done 
Java :: static block in java 
Java :: How to solve the knapsack problem, in Java? 
Java :: array to array list java 
Java :: find minimum element in a sorted and rotated array 
Java :: use custom font java 
Java :: how to declare a interface in java 
Java :: spring mvc 
Java :: top java interview coding questions 
Java :: java application 
Java :: Java short Keyword 
Java :: java pass by reference 
Java :: vim yank to clipboard 
Java :: java firebase syncrhonous data read 
Java :: java loop find index 
Java :: colors java intell print 
Java :: @embeddedid 
Java :: calculate mcd in javsa 
Java :: how to extract word from string in java 
Java :: how to stop extending jpa repository to every class in java 
Java :: trier un tableau de string java 
Java :: string to integer online 
Java :: java map get if contains else 0 
Java :: size of a tree node java linked;ist 
Java :: mergesort parallelization using spark 
Java :: unlock the screen 
Java :: mapToJsonString 
Java :: jlabel text grösse 
ADD CONTENT
Topic
Content
Source link
Name
7+6 =