Skip to main content

Posts

Showing posts from May 23, 2020

while loop in C

while loop in C: In this session we are going to discuss about while loop and do while loop in C. If you have not red the first session in which I have discussed about for loop the link for the same will be present below this article. 1. while loop in C: As we have seen earlier in for loops it requires initialization, condition, increment or decrement directly after it is declared as shown below. for(initialization, condition, increment) But the same is not true in the case of while loop in while loop the initialization is done first outside the loop, the condition is written after the loop and the increment or decrement operator within the loop. Basic Syntax: int i=1; ← (initialization) while (condition) { code if condition is true; i++; ←  (increment operator) } Explanation: From the above syntax we can see that the initialization (i=1) is done before the loop is executed. The condition for which loop is executed  is written within parenthesis