Worksheets › Class 6 › Loops and Conditions › Cheat sheet
Class 6 Loops and Conditions: cheat sheet
CBSE Computational Thinking and AI. A loop repeats steps; a condition (if–otherwise) chooses which step to do. Tracing a loop means tracking the values round by round.
Key ideas
- A loop repeats a set of steps, so we do not have to write them again and again.
- “Repeat k times” runs exactly k times; a while loop runs as long as its condition is true.
- A variable is a name that stores a value, like x or score; “x = x + 2” makes x two more.
- In a nested loop, the inner loop runs fully on every round of the outer loop.
- An if–otherwise rule checks a condition each round and does only one of the two steps.
- A robot drawing a regular shape turns a total of 360°, so each turn is 360° ÷ the number of sides.
Remember
| Count from a to b in steps of s | (last number said − a) ÷ s + 1 |
| x = a, repeat k times: x = x + d | x = a + k × d |
| x = a, repeat k times: x = x × 2 | x = a × 2ᵏ |
| Repeat a times (repeat b times: clap) | a × b claps |
| Turn for a regular shape with n sides | 360° ÷ n (square: 90°, hexagon: 60°) |
| While the box has less than ₹T, add ₹d | stop at the first total of ₹T or more |
Watch out
- Missing the first or the last number when counting the rounds of a loop.
- Adding the inner and outer counts instead of multiplying them.
- Stopping a while loop one round early: check the condition again after every round.
Worked example
(a) Start with n = 18. While n is 84 or less: say n, then add 4 to n. How many numbers are said? (b) Isha's box has ₹30. While the box has less than ₹745: add ₹50 and count one day. How many days are counted?
Working: (a) 18, 22, …, 82: (82 − 18) ÷ 4 + 1 = 17; (b) ₹30 + 15 × ₹50 = ₹780, which is the first total of ₹745 or more
Answer: (a) 17; (b) 15
Practise Loops and Conditions
Revise with this page, then practise: every Loops and Conditions sheet in the app is new, with an answer key and working.
Coming soon for Android and iPhone.