Include stdio h int main () int i 10 while i 20 printf \na computer buff ); return 0
In this tutorial, you will learn to create while and do...while loop in C programming with the help of examples. Show Video: C while Loop
In programming, loops are used to repeat a block of code until a specified condition is met. C programming has three types of loops.
In the previous tutorial, we learned about while loopThe syntax of the
How while loop works?
To learn more about test expressions (when Flowchart of while loopWorking of while loopExample 1: while loop
Output 1 2 3 4 5 Here, we have initialized i to 1.
do...while loopThe The syntax of the
How do...while loop works?
Flowchart of do...while LoopWorking of do...while loopExample 2: do...while loop
Output Enter a number: 1.5 Enter a number: 2.4 Enter a number: -3.4 Enter a number: 4.2 Enter a number: 0 Sum = 4.70 Here, we have used a The
So, if the
first input is a non-zero number, that number is added to the sum variable and the loop continues to the next iteration. This process is repeated until the user enters But if the first input is 0, there will be no second iteration of the loop and sum becomes Outside the loop, we print the value of sum. |