while Loop Structure

The while loop works by following a very structured top-down approach that can be divided into the following parts:

  1. Initialization: In this step, we initialize the loop variable to some initial value. Initialization is not part of while loop syntax but it is essential when we are using some variable in the test expression
     
  2.  Conditional Statement: This is one of the most crucial steps as it decides whether the block in the while loop code will execute. The while loop body will be executed if and only the test condition defined in the conditional statement is true.
     
  3. Body: It is the actual set of statements that will be executed till the specified condition is true. It is generally enclosed inside { } braces.
     
  4. Updation: It is an expression that updates the value of the loop variable in each iteration. It is also not part of the syntax but we have to define it explicitly in the body of the loop.

while loop in C

The while Loop is an entry-controlled loop in C programming language. This loop can be used to iterate a part of code while the given condition remains true.

Similar Reads

Syntax

The while loop syntax is as follows:...

Example

The below example shows how to use a while loop in a C program...

while Loop Structure

...

Flowchart of while loop in C

The while loop works by following a very structured top-down approach that can be divided into the following parts:...

Working of while Loop

...

Infinite while loop

We can understand the working of the while loop by looking at the above flowchart:...

Important Points

An infinite while loop is created when the given condition is always true. It is encountered by programmers in when:...