Back to Topic 6.3 — Programming constructs
6.3.3Computer Science SL5 flashcards

Loops

Practice Flashcards

Flip to reveal answers
Card 1 of 56.3.3
6.3.3
Question

How do you choose between a counted and a conditional loop?

Click to reveal answer

Track your progress — Sign up free to save your progress and get smart review reminders based on spaced repetition.

All 5 Flashcards — Loops

Sign up free to track progress and get spaced-repetition review schedules.

Card 1process

Question

How do you choose between a counted and a conditional loop?

Answer

Ask whether you know how many times it must repeat before it starts. Yes means a counted loop (for); no means a conditional one (while), which repeats as long as a condition holds.

Card 2concept

Question

How many times does a counted loop of 5 run, and what values does the counter take?

Answer

Five times, taking 0, 1, 2, 3 and 4. It starts at 0 and stops before 5 — the same rule as a string slice, and the same source of off-by-one errors.

Card 3concept

Question

Can a while loop run zero times?

Answer

Yes. The condition is tested before the first pass, so if it is already false the body never runs at all. That is correct behaviour and often exactly what is wanted.

Card 4concept

Question

Where should a counter or total be set up?

Answer

Before the loop. Setting it inside resets it on every pass, so the final answer would be just the last value rather than the accumulated one.

Card 5concept

Question

Why do nested loops produce O(n²) work?

Answer

The inner loop runs completely for every single pass of the outer loop, so the total work is rows times columns. That is where quadratic complexity comes from.

Track your progress with spaced repetition

Sign up free — Aimnova tells you exactly which cards to review and when, so you remember everything before your IB exam.

Start Free