W7Code » C Language » While Loop in C Programming Language

Sometimes we need repeat an instruction a certain number of times, so we use the while loop in c programming language. At each execution of a cycle we call iteration.

While Loop Syntax

 

Explained Condition:

  1. In while loop the condition is evaluated, if returns false the cycle ends, and continues one the closing of the while loop } .
  2. if the condition returns true, the cycle will executed and tested while the condition is true, and then, ends the cycle.

 

Example

 

Code Explained

  • line4, we declare the variable ‘‘ of type integer, and set the value to 1;
  • line6 and line9, we use the while loop and establish the condition ” i <= 10 “, that will be repeated 10 times;
  • line5, we print the variable ;
  • line6, we increment the value of variable in 1.
    • i++ it equal to i = i + 1

 

Output:

 

Examples of programs

Create all Math tables

Output

Leave a Reply