C while loop

Last Updated Nov 20, 2015, 07:00:14 PM





while loop in C programming allos code to be executed repeatedly based on a given boolean condition becomesFALSE.
c for loop

Syntax



The while loop consists of a block of code to execute and a boolean condition to test the expression. During the evaluation of the condition the code within the block is executed if the condition is TRUE

The condition evaluation repeats the process until the expression becomes FALSE



Try It Now

In the above while loop example, the initial value of n is ZERO and in the last line we are keep increasing the value of n n++ In the while loop we are increasing the n value by one until n < 10. So if the value of n becomes greater than 10? then the loop terminates

First it checks whether n is less than 10, which it is, so then the {loop body} is entered, where the printf function is run and x is incremented by 1. After completing all the statements in the loop body, the condition, (n < 10), is checked again, and the loop is executed again, this process repeating until the variable x has the value 10.



Difference between While loop and Do while loop in C

The do while loop executes the content of the loop once before checking the condition of the while. Whereas a while loop will check the condition first before executing the content.



Why use a for loop instead of a while loop? - StackOverFlow

Other Loop Topics you might want to learn

for loop in C

do..while loop in C

nested loops in C