Technology has advanced to the point where programming has become an essential part of our lives. We use software and applications for communication, entertainment, education, and work, and these are all built on programming languages.

Looping

Loop is used in programming to execute any instruction repeatedly until a condition is satisfied. The computer has ability to perform a set of instructions repeatedly. This involves repetition of some portion of a program either for a specified number of times or till a given condition is satisfied. This repetition operation is known as looping.

Purpose of Looping
  • To execute statements for a specified number of times.
  • To use a sequence of values.
Types of Loop in C programming
  1. While Loop
  2. do while Loop
  3. For loop
While Loop
It execute one or more statements while the given condition remains true. It is useful when number of iterations is unknown. It is also called entry control or pre test loop.
fig: Flowchart of while loop


do while Loop
do while loops are useful where loop is to be executed at least once. In do while loop condition comes after the body of loop. The loop executes one or more statements while the given condition is true. It is an exit control or post test loop.



 Fig: Flowchart to show do while loop

For loop
For loop allows to specify three things about loop in a single line. For loops are used when the number of iterations is known before entering the loop. It is also known as counter controlled loop.


 Fig: Flowchart to show execution of for loop
Share:

No comments:

Post a Comment

If you have any doubt, let me know...

Translate

Wikipedia

Search results