Worksheets › Class 11 › Flow of Control › Cheat sheet

Class 11 Flow of Control: cheat sheet

CBSE Computer Science. if, elif and else choose what runs; for with range() and while repeat it; break and continue change a loop; nested loops print patterns.

Open the printable cheat sheetPractice worksheet

Key ideas

Remember

range()list(range(5)) = [0, 1, 2, 3, 4]; list(range(1, 10, 3)) = [1, 4, 7]
Adding 1 to nsum of range(1, n + 1) = n(n + 1)/2: 1 to 10 gives 55
Nested loopsrange(3) inside range(4): the inner body runs 12 times
Special numbersArmstrong: 153 = 1³ + 5³ + 3³; perfect: 28 = 1 + 2 + 4 + 7 + 14
breakfor i in range(1, 30):     if i * i > 50:         break print(i) # 8
continuefor i in range(1, 8):     if i % 3 == 0:         continue     print(i, end=' ') # 1 2 4 5 7

Watch out

Worked example

What are a, b and c after these lines run? a, b, c = 72, 52, 86 if a > b:     a, b = b, a if b > c:     b, c = c, b if a > b:     a, b = b, a

Working: each swap puts the smaller value first: the three numbers end up sorted

Answer: a = 52, b = 72, c = 86

Practise Flow of Control

Revise with this page, then practise: every Flow of Control sheet in the app is new, with an answer key and working.

Coming soon for Android and iPhone.