while Loop Structure
The while loop works by following a very structured top-down approach that can be divided into the following parts:
- 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
- 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.
- Body: It is the actual set of statements that will be executed till the specified condition is true. It is generally enclosed inside { } braces.
- 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.