Computer Science · Class 11 Optional
Ch 6Flow of Control — Class 11 Computer Science, concept-first.
Every program has an order in which its statements run, and controlling that order is what this chapter is about. The textbook opens with a simple picture: a school bus taking children to school along a road that offers exactly one route (Figure 6.1).
Key concepts
Hover a concept to preview it and jump to its most relevant Q&A.
String Input Type
Imagine you're writing a program that asks someone for their name. The user types "Ravi" and presses Enter. What just arrived inside your program? A string — a sequence of characters: 'R', 'a', 'v', 'i'.
Most relevant Q&A
Chapter contents
The NCERT structure, section by section. Open a section to see its questions, then read the concept-first solution.
Introduction
Every program has an order in which its statements run, and controlling that order is what this chapter is about.
+−Programs1 question
Selection
5 QReal life is full of decisions. Standing in a stationery shop with 10 rupees, you find several different pens all priced at 10 rupees each — you must choose one.
+−Worked Examples1 question
+−Worked Examples1 question
+−Worked Examples1 question
+−Programs1 question
Indentation
How does Python know which statements belong to the if block and which come after it? Most programming languages answer this by wrapping the statements of a block inside curly brackets.
Repetition
Many tasks in daily life repeat: the electricity bill is paid every month, seasons return every year. Nature repeats too — Figure 6.3 shows the life cycle of a butterfly, which passes through four sta…
The ‘For’ Loop
5 QThe for statement is used to iterate over a range of values or a sequence. The loop body executes once for each item in that range.
+−Worked Examples1 question
+−Programs1 question
+−Programs1 question
+−Programs1 question
The ‘While’ Loop
2 QThe while statement executes a block of code repeatedly as long as the control condition of the loop is true.
Break and Continue Statement
Looping constructs let a programmer repeat tasks efficiently — but sometimes the normal round-and-round flow of a loop needs to be interrupted.
Break Statement
3 QThe break statement alters the normal flow of execution: it terminates the current loop immediately and resumes execution at the statement following that loop.
+−Programs1 question
+−Programs1 question
Continue Statement
Where break abandons a loop entirely, the continue statement abandons only the current iteration. When continue is encountered, control skips the remaining statements in the body of the loop for that…
Nested Loops
4 QA loop may contain another loop inside its body. A loop placed inside another loop is called a nested loop.
+−Programs1 question
+−Programs1 question
+−Programs1 question
Summary
- The order in which the statements of a program are executed is called the flow of control; it is shaped using control structures, of which Python supports two types — selection and repetition.
Exercises
+−Show 5 questionsHide questions5 questions
- Q1What is the difference between else and elif construct of if statement?Free
- Q2What is the purpose of range() function? Give one example.Free
- Q3Differentiate between break and continue statements using examples.Preview
- Q4What is an infinite loop? Give one example.Preview
- Q5Find the output of the following program segments: (i) a = 110 while a > 100: print(a) a -= 2 (ii) for i in range(20,30,2): print(i) (iii) c…Preview
More questions
11 Q+−Show 10 questionsHide questions10 questions
- Q1Write a program that takes the name and age of the user as input and displays a message whether the user is eligible to apply for a driving…Free
- Q2Write a function to print the table of a given number. The number has to be entered by the user.Free
- Q3Write a program that prints minimum and maximum of five numbers entered by the user.Free
- Q4Write a program to check if the year entered by the user is a leap year or not.Preview
- Q5Write a program to generate the sequence: –5, 10, –15, 20, –25….. upto n, where n is an integer input by the user.Preview
- Q6Write a program to find the sum of 1+ 1/8 + 1/27......1/n^3, where n is the number input by the user.Preview
- Q7Write a program to find the sum of digits of an integer number, input by the user.Preview
- Q8Write a function that checks whether an input number is a palindrome or not. [Note: A number or a string is called palindrome if it appears…Preview
- Q9Write a program to print the following patterns: i) * * * * * * * * * * * * * ii) 1 2 1 2 3 2 1 2 3 4 3 2 1 2 3 4 5 4 3 2 1 2 3 4 5 iii) 1 2…Preview
- Q10Write a program to find the grade of a student when grades are allocated as given in the table below. | Percentage of Marks | Grade | | ---…Preview