Header Ads Widget

Loops in C Programming

Suppose we want to print XYZ 100 times,then to get desired output -
(1) We can use  printf("XYZ");  statement 100 times or
(2) We can use loops.
Loops allow a set of instructions to be repeatedly executed until certain condition is reached. This condition may be predetermined or open ended. The test expression is always involves a variable, which is known as loop control variable. In addition to test expression, two other processes are associated with loops - initialization and updating. Initialization  is statement that assigns the initial value of loop control variable. The updating statement updates the value of loop control variable in each iteration.
C has three loop constructs - while, for and do-while.  while and for are pre-test loops and do-while is post test loop.

Post a Comment

0 Comments