Grade 11 Exam  >  Grade 11 Notes  >  Computer Science  >  Flow of Control

Flow of Control

Introduction

The order of execution of the statements in a program is known as flow of control. The flow of control can be implemented using control structures. Python supports two types of control structures-Selection and Repetition.

Indentation

  • Leading whitespace (spaces and tabs) at the beginning of a statement is called indentation.
  • Python uses indentation for block as well as for nested block structures.
  • In Python, the same level of indentation associates statements into a single block of code. The interpreter checks indentation levels very strictly and throws up syntax errors if indentation is not correct. It is a common practice to use a single tab for each level of indentation.

Types of Flow of Control
There are three types of flow of control -

a) Sequential flow of control

In Sequential flow of control execution of statement takes place in a sequence i.e. top to bottom approach.
num = int (input ("Enter Number " ))
num = num * 5
print (num) 

b) Conditional flow of control

Conditional flow of control is use to execute set of statements on the basis of the conditions.

Indentation

num = int(input("Enter a number : "))
if num % 5 == 0:
print(num, "is divisible by 5")
else:
print(num, "is not divisible by 5")

c) Iterative flow of control

iterative flow of control means repetition. It execute the set of statements till the condition is true.

Indentation

Conditional statements

  • An if statement tests a particular condition; if the condition evaluates to true, then set of statements executed otherwise does not.

 if <conditional expression > :
statement
[statements] 

# Write a program to check given character is an alphabet 'A'.
ch = input("Enter a character : ")
if ch == 'A' :
print("You entered alphabet A")
if ch != 'A' :
print("You entered alphabet A")

The if-else Statement

  • An if statement tests a particular condition; if the condition evaluates to true, then it carries out the  statements indented below if and in case condition evaluate to false, it carries out statements indented below else.

if <conditional expression > :
statement
[statements]
else :
statement
[statements] 

Conditional statements

# Write a program to check given character is an upper alphabet.

ch = input("Enter a character : ")
if ch >= 'A' and ch <= 'Z':
print("You have entered Upper alphabet")
else:
print("You have entered other than Upper Alphabet")
The if-elif-else

  • An if-elif statement provide a facility to tests a condition with else ;

Syntax - 1
if <conditional expression > :
statement
[statements]
elif <conditional-expression> :
statement
[statements] 

Syntax - 2
 if <conditional expression > :
statement
[statements]
elif <conditional-expression>:
statement
[statements]
else:
statement
[statements] 

# Write a program to check given character is an upper alphabet, lower alphabet, digits or other symbol.
ch = input("Enter a character : ")
if ch >= 'A' and ch <= 'Z':
print("You have entered Upper alphabet")
elif ch >= 'a' and ch <= 'z':
print("You have entered Lower alphabet")
elif ch >= '0' and ch <= '9':
print("You have entered Digit")
else:
print("You have entered Symbol")

Nested if statements

  • An if inside the another if, called Nested if's statement.
  • An if-else inside the another if or else called nested if-else.

 if <conditional expression > :
if <condition>:
statements
else:
statements
else :
if <condition>:
statements
else:
statements 

Sample Programs :
# Absolute value
num = int(input("Enter a Number : "))
if num > 0 :
print("Absolute Value is ", num)
elif num < 0:
print("Absolute Value is ", num * -1)
else:
print("You have entered ", num)

# Sort 3 numbers
num1 = int(input("Enter a Number 1 : "))
num2 = int(input("Enter a Number 2 : "))
num3 = int(input("Enter a Number 3 : "))
if num1 < num2 and num1 < num3:
if num2 < num3:
print(num1, num2, num3)
else:
print(num1, num3, num2)
elif num2 < num1 and num2 < num3:
if num1 < num3:
print(num2, num1, num3)
else:
print(num2, num3, num1)
else:
if num2 < num1:
print(num3, num2, num1)
else:
print(num3, num1, num2)

# Divisibility of a number
num1 = int(input("Enter a Number 1 : "))
num2 = int(input("Enter a Number 2 : "))
if num1 % num2 == 0 :
print(num1 "is divisible by", num2)
elif num2 % num1 == 0:
print(num2, "is divisible by", num1)
else:
print(num1, 'and', num2,'neighter factor nor multiples')

Iterative / Repetitive Statements / Looping

range() function
for loop
while loop,
Flow Charts
Nested loops,

Suggested Programs:
# Python programs for generating pattern
Pattern-1
*
* *
* * *
* * * *
* * * * *
# Python Programs for summation of series.
# Finding the factorial of a positive number.

The document Flow of Control is a part of the Grade 11 Course Computer Science for Grade 11.
All you need of Grade 11 at this link: Grade 11

FAQs on Flow of Control

1. What's the difference between if, else if, and else statements in flow control?
Ans. If statements execute code when a condition is true, else if checks additional conditions if the first is false, and else runs when all previous conditions fail. Together, they create branching logic that directs program execution along different paths based on specific criteria, forming the foundation of conditional statements in CBSE Computer Science.
2. Why does my loop keep running forever instead of stopping?
Ans. Infinite loops occur when the loop's exit condition never becomes false. Common causes include forgetting to increment/decrement the counter variable, setting incorrect loop conditions, or using operators like == instead of !=. Always verify that loop variables change and conditions will eventually be met to prevent endless execution.
3. How do switch statements work compared to multiple if-else blocks?
Ans. Switch statements evaluate a single expression once and jump to matching cases, making them more efficient than multiple if-else comparisons. They're cleaner for checking one variable against many fixed values. However, if-else suits complex conditional logic better. Both control program flow differently-switch is optimised for discrete value matching.
4. What's the purpose of break and continue statements in loops?
Ans. Break statements immediately exit a loop, skipping remaining iterations entirely. Continue statements skip only the current iteration and jump to the loop's next cycle. Both are loop control statements that alter normal execution flow. Break is used for premature termination; continue for bypassing specific iterations based on conditions.
5. How do nested loops work and when should I use them in CBSE programs?
Ans. Nested loops place one loop inside another, creating multiple levels of iteration-the inner loop completes fully before the outer loop advances. They're essential for processing 2D arrays, creating patterns, and handling matrix operations. Understanding nested loop flow prevents logical errors; refer to mind maps and visual worksheets on EduRev for practical examples.
Explore Courses for Grade 11 exam
Get EduRev Notes directly in your Google search
Related Searches
Previous Year Questions with Solutions, Extra Questions, Flow of Control, practice quizzes, Exam, MCQs, Important questions, pdf , Semester Notes, study material, mock tests for examination, video lectures, Viva Questions, Flow of Control, ppt, Sample Paper, Free, Objective type Questions, shortcuts and tricks, Summary, Flow of Control, past year papers;