Loop Control Structure. Presented By: Sallar Khan
Contents What is Loop ? For Loop While Loop Do While Loop Breaking out of Loop Continue to the next Loop Loop with Conditional Statement Switch Statement
What is Loop ? When a block of code needs to be executed several number of times. In general, statements are executed sequentially: The first statement in a function is executed first, followed by the second, and so on.
..Loop (Cont.) A loop statement allows us to execute a statement or group of statements multiple times. Given figure is the general form of a loop statement in most of the programming languages.
For Loop A for loop is a repetition control structure that allows you to efficiently write a loop that needs to execute a specific number of times.
..For Loop (Example) OUTPUT
While Loop The while loop checks whether the test expression is true or not. If it is true, code/s inside the body of while loop is executed, that is, code/s inside the braces { } are executed. Then again the test expression is checked whether test expression is true or not. This process continues until the test expression becomes false.
..While Loop(Cont.) Flow Diagram
..While Loop (Example) OUTPUT
Do While Loop In C, do...while loop is very similar to while loop. Only difference between these two loops is that, in while loops, test expression is checked at first but, in do...while loop code is executed at first then the condition is checked. So, the code are executed at least once in do...while loops.
..Do While Loop (Example) OUTPUT
Thank You!