C++ While loop

tutorial and example
tutorial and example

C++ while Loop Statement

The while loop is an iterative control statement. A while loop repeatedly executes loop’s statement(s) several times as a given condition is true. Execution of loop is terminated when the condition of while loop become false and execute code after loop.


Working Process Of While Loop

  1. While loop first checks the condition applied.
  2. If condition of while loop is satisfied (true), statement(s) within loop is executed. If condition of while loop is not satisfied (false), program execution is terminated from loop and statement after the loop is executed.
  3. Repeatedly check the loop condition and execute according to step 2.

C++ while loop Example

This program prints counting from 1 to 10.