Flowchart and Loops
Flowchart and Loops
6. Flow lines: Flow lines indicate the exact sequence in which instructions are
executed. Arrows represent the direction of flow of control and relationship
among different symbols of flowchart.
Rules For Creating Flowchart:
A flowchart is a graphical representation of an algorithm.it should follow some rules
while creating a flowchart
Rule 1: Flowchart opening statement must be ‘start’ keyword.
Rule 2: Flowchart ending statement must be ‘end’ keyword.
Rule 3: All symbols in the flowchart must be connected with an arrow line.
Rule 4: The decision symbol in the flowchart is associated with the arrow line.
Advantages of Flowchart:
Flowcharts are a better way of communicating the logic of the system.
Easy to understand.
Disadvantages of Flowchart:
It is difficult to draw flowcharts for large and complex programs.
Example: Draw a flowchart to input two numbers from the user and display the
largest of two numbers.
Loops in programming are used to repeat a block of code until the specified condition
is met. A loop statement allows programmers to execute a statement or group of
statements multiple times without repetition of code.
2. Exit Controlled loops: In Exit controlled loops the test condition is evaluated at
the end of the loop body. The loop body will execute at least once, irrespective of
whether the condition is true or false. do-while Loop is Exit Controlled loop.
Loop Type Description
first Initializes, then condition check, then executes the body and at
for loop
last, the update is done.
first Initializes, then condition checks, and then executes the body, and
while loop
updating can be inside the body.
do-while loop do-while first executes the body and then the condition check is done.
Name Description
break statement the break statement is used to terminate the switch and loop
Name Description
goto statement goto statement transfers the control to the labeled statement.
Infinite Loop
An infinite loop is executed when the test expression never becomes false and the body
of the loop is executed repeatedly. A program is stuck in an Infinite loop when the
condition is always true. Mostly this is an error that can be resolved by using Loop
Control statements.