FuzzDuck
FuzzDuck
Do while
FuzzDuck
Do while

Do while

Another variant of the while loop is the do while loop. With the do while loop, we execute code and then checks whether it is going to be executed again. The difference of the while loop and the do while loop, is that the while loop checks whether the condition is met before executing its content. The do while loop does it the other way around, executing its content and then checks whether the condition is met, or if it needs to be run again.

Code Example - While iteration
// --- Declaring starting point of the program run with "main" method --- //
public static void Main(string[] args){

 // --- Declaring int "number" to iterate through --- //
 int number = 1;

 // --- Iterating through "number" 5 at least once and for as long as number is lower than 5 --- //
 do {
  Console.WriteLine("Running for the " + number + ". time");
  number++;
 } while (number < 5);

 // --- Invoking 'ReadKey()' to make time to read the output --- //
 Console.ReadKey();

}
// --- Declaring starting point of the program run with "main" method --- //
public static void main(String [ ] args){

 // --- Declaring int "number" to iterate through --- //
 int number = 1;

 // --- Iterating through "number" 5 at least once and for as long as number is lower than 5 --- //
 do {
  System.out.println("Running for the "+ number + ". time");
  number++;
 } while (number < 5);

}
// --- Declaring int "number" to iterate through --- //
$number = 1;

// --- Iterating through "number" 5 as long as it is lower than 5 --- //
do {
 echo "Running for the " . $number . ". time <br>";
 $number++;
} while ($number < 5)

From the code above the outcome below is generated

Running for the 1. time
Running for the 2. time
Running for the 3. time
Running for the 4. time