aimnova.
DashboardMy LearningPaper MasteryStudy Plan

Aimnova site navigation

Stay in the loop

Get the latest study resources and updates

New features, study tips and exam insights — straight to your inbox.

IB Diploma

  • IB Past Papers
  • IB Study Notes
  • IB Question Bank
  • IB Mock Exams
  • IB Revision

IB Subjects

  • IB Math AA
  • IB Math AI
  • IB Economics
  • IB Business Management
  • IB Physics
  • IB Biology
  • View all IB subjects→

IB Past Papers

  • IB Math AA HL Past Papers
  • IB Math AA SL Past Papers
  • IB Math AI HL Past Papers
  • IB Math AI SL Past Papers
  • IB Economics HL Past Papers
  • IB Economics SL Past Papers
  • IB ESS Past Papers
  • View all past papers→

Study Resources

  • Study Notes
  • Question Bank
  • Mock Exams
  • Flashcards
  • Revision Guide
  • Exam Skills
  • Command Terms
  • Grade Calculator
  • Exam Timetable 2026

Aimnova

  • Features
  • Pricing
  • For Schools
  • For Parents
  • About Us
  • Blog
  • Contact
aimnova.

AI-powered study platform for smarter revision, past-paper analysis and examiner-style feedback.

TermsPrivacyCookies·© 2026 Aimnova. All rights reserved.8afc4e3

Aimnova is not affiliated with or endorsed by the International Baccalaureate Organization (IB).

NotesComputer ScienceTopic 6.3Loops
Back to Computer Science Topics
6.3.35 min read

Loops

IB Computer Science • Unit 6

AI-powered feedback

Stop guessing — know where you lost marks

Get instant, examiner-style feedback on every answer. See exactly how to improve and what the markscheme expects.

Try It Free

Contents

  • Doing something more than once
  • Counted or conditional
  • Conditions inside loops
  • Exam-style question
The big idea: A loop repeats a block of code.

The only real question is what decides when to stop: a count you already know, or a condition you keep testing.
A counted loop of 5 runs 0 to 4: Five values, starting at 0 and stopping before 5.

The same rule as string slices, and the same source of off-by-one errors.

Free preview

This is the free notes preview

You're reading the free notes. Aimnova Pro unlocks the full study experience — and you can try it with your first topic free to keep:

  • FlashcardsLock in vocabulary and key terms with spaced repetition.
  • Practice questionsAnswer exam-style questions and get instant AI marking.
  • Mock exams & past-paper vaultSit full mocks and see exactly how examiners award marks.
  • Personalised study planA daily plan built around your exam date and weak areas.
Start Studying Free Full access to Aimnova Pro · cancel anytime

Counted — for

  • The number of repeats is known before it starts
  • The counter is managed for you, so it cannot be forgotten
  • Cannot loop forever by accident
  • Right for: every item in a list, a fixed number of attempts, rows in a grid

Conditional — while

  • Repeats as long as a condition holds
  • May run any number of times, including none at all
  • You must change what the condition depends on
  • Right for: waiting for valid input, reading until end of file, repeating until solved
The choosing question: Do I know how many times before I start?

Yes → counted loop. No → conditional loop. Answering it first prevents most loop problems.
A while loop may run zero times: The condition is tested before the first pass.

If it is already false, the body never runs at all — which is correct behaviour, and is often exactly what you want.

Memorize terms 3x faster

Smart flashcards show you cards right before you forget them. Perfect for definitions and key concepts.

Try Flashcards FreeYour first topic is free to keep • No credit card required
1

if inside a loop

2

break — leave early

3

Nested loops

4

Validation loops

The infinite-loop check: In any while loop, point at the line that changes what the condition tests.

If you cannot find it, or it sits inside an if that might not run, the loop can go on forever.

How this is tested — you must choose the right loop and get the number of repeats exactly right. It comes up two ways:

Paper 2 — working with code

  • Construct a loop for a described task, 3-5 marks
  • Trace a loop and state the output
  • Explain why a loop runs the wrong number of times

Paper 2 — the algorithmic-thinking question

  • Choose counted or conditional from a description
  • Explain how a loop terminates, with no code shown
The classic trap: Off by one on the repeat count. A counted loop of 5 runs 0 to 4, and a while loop tests before each pass — so it may run zero times. Trace the first and last passes explicitly.
IB-style questionConstruct[5 marks]

A program asks for marks until the user types -1, then prints how many were entered and how many were passes (50 or more). Write it.

Model answer plan

See the mark-by-mark plan — for / against / judgement, with marking guidance — in study mode.

Claim your free topic

Try an IB Exam Question — Free AI Feedback

Test yourself on Loops. Write your answer and get instant AI feedback — just like a real IB examiner.

how many times the body runs in: FOR i FROM 0 TO 20 STEP 5. [2 marks]

Related Computer Science Topics

Continue learning with these related topics from the same unit:

6.1.1Variables and data types
6.1.2Substrings
6.1.3Exception handling
6.1.4Debugging
View all Computer Science topics

Improve your exam technique

Command terms, paper structure, and mark-scheme tips for Computer Science

Previous
6.3.2Selection
Next
Functions and modularity6.3.4

25 exam-style questions ready for you

Students who practice on Aimnova improve their scores by 15% on average. Get instant feedback that shows exactly how to improve your answers.

Practice Now — FreeView All Computer Science Topics