Flow of Control – NCERT Class 11 Computer Science Chapter 6 – Conditional and Looping Constructs in Python

Explains how Python manages the order of execution of statements using control structures. Covers conditional statements (if, if-else, if-elif), indentation rules, and looping constructs (for and while). Introduces range() function, nested loops, and the use of break and continue statements with various examples. Highlights flowcharts, iteration logic, and pattern generation for better understanding of program control flow.

Updated: just now

Categories: NCERT, Class XI, Computer Science, Python, Flow of Control, Conditional Statements, Looping, Chapter 6
Tags: Flow of Control, Conditional Statements, If Else, Elif, Loops, For Loop, While Loop, Range Function, Break Statement, Continue Statement, Nested Loops, Indentation, Decision Making, Iteration, NCERT Class 11, Computer Science, Chapter 6
Post Thumbnail
Flow of Control: NCERT Class 11 Chapter 6 - Enhanced Study Guide, Precise Notes, Diagrams & Quiz 2025

Flow of Control

Chapter 6: Enhanced NCERT Class 11 Guide | Expanded Precise Notes from Full PDF, Detailed Explanations, Diagrams, Examples & Quiz 2025

Enhanced Full Chapter Summary & Precise Notes from NCERT PDF (22 Pages)

Overview & Key Concepts

Exact Definition: "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."

  • Introduction: Sequence from Ch 5; Bus analogy (Fig 6.1); Quote: G. van Rossum on indentation.
  • Chapter Structure: Selection (if/else/elif), Indentation, Repetition (for/while), Break/Continue, Nested Loops.
  • 2025 Relevance: Control in AI loops (e.g., TensorFlow training); Indentation in VS Code; Nested for data processing.

6.1 Introduction to Flow of Control

Precise: Sequential execution; Control structures: Selection/Repetition. Expanded: Program 6-1 (difference); Flow like bus route.

Precise Fig 6.1: Bus to School (SVG)

Sequential Flow Bus follows one path Milestone after milestone To school (end) End

Program 6-1: Difference of Two Numbers

#Program 6-1 #Program to print the difference of two input numbers num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) diff = num1 - num2 print("The difference of",num1,"and",num2,"is",diff)

Output:
Enter first number 5
Enter second number 7
The difference of 5 and 7 is -2

6.2 Selection

Precise: Decision making (if/else/elif); Positive difference (Prog 6-2); Flowchart Fig 6.2. Expanded: Nested if in calculator (Prog 6-3).

Precise Fig 6.2: Decision Flowchart (SVG)

Start Input num1, num2 num1 > num2? diff = num1 - num2 diff = num2 - num1 Print diff

Program 6-2: Positive Difference

#Program 6-2 #Program to print the positive difference of two numbers num1 = int(input("Enter first number: ")) num2 = int(input("Enter second number: ")) if num1 > num2: diff = num1 - num2 else: diff = num2 - num1 print("The difference of",num1,"and",num2,"is",diff)

Output:
Enter first number: 5
Enter second number: 6
The difference of 5 and 6 is 1

Program 6-3: Simple Calculator

#Program to create a four function calculator result = 0 val1 = float(input("Enter value 1: ")) val2 = float(input("Enter value 2: ")) op = input("Enter any one of the operator (+,-,*,/): ") if op == "+": result = val1 + val2 elif op == "-": if val1 > val2: result = val1 - val2 else: result = val2 - val1 elif op == "*": result = val1 * val2 elif op == "/": if val2 == 0: print("Error! Division by zero is not allowed. Program terminated") else: result = val1/val2 else: print("Wrong input,program terminated") print("The result is ",result)

Output:
Enter value 1: 84
Enter value 2: 4
Enter any one of the operator (+,-,*,/): /
The result is 21.0

Example 6.1: if Syntax

age = int(input("Enter your age ")) if age >= 18: print("Eligible to vote")

Example 6.2: if-elif-else (Positive/Negative/Zero)

number = int(input("Enter a number: ")) if number > 0: print("Number is positive") elif number < 0: print("Number is negative") else: print("Number is zero")

Example 6.3: Traffic Signal

signal = input("Enter the colour: ") if signal == "red" or signal == "RED": print("STOP") elif signal == "orange" or signal == "ORANGE": print("Be Slow") elif signal == "green" or signal == "GREEN": print("Go!")

6.3 Indentation

Precise: Whitespace for blocks; Strict check; Single tab common. Expanded: Prog 6-4 shows blocks.

Program 6-4: Larger of Two Numbers

#Program 6-4 #Program to find larger of the two numbers num1 = 5 num2 = 6 if num1 > num2: #Block1 print("first number is larger") print("Bye") else: #Block2 print("second number is larger") print("Bye Bye")

Output:
second number is larger
Bye Bye

6.4 Repetition

Precise: Loops for iteration; Butterfly cycle (Fig 6.3); For/While. Expanded: Prog 6-5 (sequence); Range() function.

Precise Fig 6.3: Iterative Process (SVG)

Eggs Caterpillar Pupa Butterfly

Program 6-5: First Five Natural Numbers

#Program 6-5 #Print first five natural numbers print(1) print(2) print(3) print(4) print(5)

Output:
1
2
3
4
5

Program 6-6: Print 'PYTHON' Characters

#Program 6-6 #Print the characters in word PYTHON using for loop for letter in 'PYTHON': print(letter)

Output:
P
Y
T
H
O
N

Program 6-7: Print Sequence [10,20,30,40,50]

#Program 6-7 #Print the given sequence of numbers using for loop count = [10,20,30,40,50] for num in count: print(num)

Output:
10
20
30
40
50

Program 6-8: Even Numbers

#Program 6-8 #Print even numbers in the given sequence numbers = [1,2,3,4,5,6,7,8,9,10] for num in numbers: if (num % 2) == 0: print(num,'is an even Number')

Output:
2 is an even Number
4 is an even Number
6 is an even Number
8 is an even Number
10 is an even Number

Example 6.4: range() Function

>>> list(range(10)) [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] >>> list(range(2, 10)) [2, 3, 4, 5, 6, 7, 8, 9] >>> list(range(0, 30, 5)) [0, 5, 10, 15, 20, 25] >>> list (range (0, -9, -1)) [0, -1, -2, -3, -4, -5, -6, -7, -8]

Program 6-9: Multiples of 10

#Program 6-9 #Print multiples of 10 for numbers in a given range for num in range(5): if num > 0: print(num * 10)

Output:
10
20
30
40

Precise Fig 6.4: For Loop Flowchart (SVG)

Start Initialization Test Expression? Body of Loop Increment Exit Loop

Program 6-10: First 5 Natural (While)

#Program 6-10 #Print first 5 natural numbers using while loop count = 1 while count <= 5: print(count) count += 1

Output:
1
2
3
4
5

Program 6-11: Factors of Number

#Program 6-11 #Find the factors of a number using while loop num = int(input("Enter a number to find its factor: ")) print (1, end=' ') #1 is a factor of every number factor = 2 while factor <= num/2 : if num % factor == 0: print(factor, end=' ') factor += 1 print (num, end=' ') #every number is a factor of itself

Output:
Enter a number to find its factors : 6
1 2 3 6

Precise Fig 6.5: While Loop Flowchart (SVG)

Start Initialization Test Condition? Body of While Update Statements after Loop

6.5 Break and Continue

Precise: Break: Exit loop; Continue: Skip iteration. Expanded: Prog 6-12 (break at 8); Prog 6-13 (sum positives); Prog 6-14 (prime check).

Precise Fig 6.6: Break Flowchart (SVG)

Start Loop Loop Body Break Condition? Break Next Iteration After Loop

Program 6-12: Break Demo

#Program 6-12 #Program to demonstrate the use of break statement in loop num = 0 for num in range(10): num = num + 1 if num == 8: break print('Num has value ' + str(num)) print('Encountered break!! Out of loop')

Output:
Num has value 1
Num has value 2
Num has value 3
Num has value 4
Num has value 5
Num has value 6
Num has value 7
Encountered break!! Out of loop

Program 6-13: Sum Positives

#Program 6-13 #Find the sum of all the positive numbers entered by the user #till the user enters a negative number. entry = 0 sum1 = 0 print("Enter numbers to find their sum, negative number ends the loop:") while True: entry = int(input()) if (entry < 0): break sum1 += entry print("Sum =", sum1)

Output:
Enter numbers to find their sum, negative number ends the loop:
3
4
5
-1
Sum = 12

Program 6-14: Prime Check

#Program 6-14 #Write a Python program to check if a given number is prime or not. num = int(input("Enter the number to be checked: ")) flag = 0 if num > 1 : for i in range(2, int(num / 2)): if (num % i == 0): flag = 1 break if flag == 1: print(num , "is not a prime number") else: print(num , "is a prime number") else : print("Entered number is <= 1, execute again!")

Output 1:
Enter the number to be checked: 20
20 is not a prime number
Output 2:
Enter the number to check: 19
19 is a prime number

Precise Fig 6.7: Continue Flowchart (SVG)

Start Loop Loop Body Continue Condition? Continue (Skip Rest) Next Iteration After Loop

Program 6-15: Continue Demo

#Program 6-15 #Prints values from 0 to 6 except 3 num = 0 for num in range(6): num = num + 1 if num == 3: continue print('Num has value ' + str(num)) print('End of loop')

Output:
Num has value 1
Num has value 2
Num has value 4
Num has value 5
Num has value 6
End of loop

6.6 Nested Loops

Precise: Loop inside loop; No limit on levels. Expanded: Prog 6-16 (nested for); Prog 6-17 (pattern); Prog 6-18 (primes 2-50); Prog 6-19 (factorial).

Program 6-16: Nested For

#Program 6-16 #Demonstrate working of nested for loops for var1 in range(3): print( "Iteration " + str(var1 + 1) + " of outer loop") for var2 in range(2): #nested loop print(var2 + 1) print("Out of inner loop") print("Out of outer loop")

Output:
Iteration 1 of outer loop
1
2
Out of inner loop
Iteration 2 of outer loop
1
2
Out of inner loop
Iteration 3 of outer loop
1
2
Out of inner loop
Out of outer loop

Program 6-17: Pattern

#Program 6-17 #Program to print the pattern for a number input by the user num = int(input("Enter a number to generate its pattern = ")) for i in range(1,num + 1): for j in range(1,i + 1): print(j, end = " ") print()

Output:
Enter a number to generate its pattern = 5
1
1 2
1 2 3
1 2 3 4
1 2 3 4 5

Program 6-18: Primes 2-50

#Program 6-18 #Use of nested loops to find the prime numbers between 2 to 50 num = 2 for i in range(2, 50): j= 2 while ( j <= (i/2)): if (i % j == 0): break j += 1 if ( j > i/j) : print ( i, "is a prime number") print ("Bye Bye!!")

Output:
2 is a prime number
3 is a prime number
5 is a prime number
7 is a prime number
11 is a prime number
13 is a prime number
17 is a prime number
19 is a prime number
23 is a prime number
29 is a prime number
31 is a prime number
37 is a prime number
41 is a prime number
43 is a prime number
47 is a prime number
Bye Bye!!

Program 6-19: Factorial

#Program 6-19 #The following program uses a for loop nested inside an if..else #block to calculate the factorial of a given number num = int(input("Enter a number: ")) fact = 1 # check if the number is negative, positive or zero if num < 0: print("Sorry, factorial does not exist for negative numbers") elif num == 0: print("The factorial of 0 is 1") else: for i in range(1, num + 1): fact = fact * i print("factorial of ", num, " is ", fact)

Output:
Enter a number: 5
Factorial of 5 is 120

Enhanced Features (2025)

Full PDF integration, expanded programs (6-1 to 6-19), SVGs (Figs 6.1-6.7), detailed tables/examples, 30 Q&A updated, 10-Q quiz. Focus: Hands-on control flow.

Exam Tips

Write programs (positive diff/prime/pattern); Explain syntax/flowcharts; Differentiate for/while; Use break/continue in code; Nested loop examples.