30 April 2023

A "do-while" loop is a type of loop construct used in programming to execute a block of code repeatedly until a certain condition is met. The code inside the "do" block will be executed at least once, regardless of whether the condition is true or false. After the code is executed, the condition is checked. If the condition is true, the loop will continue to run and the code inside the "do" block will be executed again. If the condition is false, the loop will terminate and execution will continue with the next statement after the loop.

Source code viewer
  1. // Example of a "do-while" loop in PHP that prints the numbers 1 to 10.
  2. $num = 1;
  3. // The code inside the "do" block will be executed at least once, regardless of whether the condition is true or false.
  4. do {
  5. echo $num . " ";
  6. $num++;
  7. // After the code is executed, the condition is checked.
  8. } while ($num <= 10);
Programming Language: PHP