MathsGenie logo
RevisionResourcesBlog
  1. Home
  2. /
  3. Student Questions
  4. /
  5. When to Use WHILE, REPEAT...UNTIL and FOR Loops

When to Use WHILE, REPEAT...UNTIL and FOR Loops

Choose the right GCSE Computer Science loop: use FOR for a known count, WHILE to test before repeating, and REPEAT...UNTIL when code must run at least once.

Share
Add as a preferred source on Google

Use a FOR loop when you know how many times to repeat. Use a WHILE loop when you need to check a condition before each repetition. Use a REPEAT...UNTIL loop when the instructions must run at least once, then continue until a condition becomes true.

A condition is a test that can be true or false. The key question is whether you know the number of repetitions in advance and when the test needs to happen.

Choosing a loop

A FOR loop is useful for a fixed number of repetitions. For example, if a program must ask five quiz questions, it can use a FOR loop to run the question-handling instructions five times.

A WHILE loop checks its condition before running the instructions each time. It keeps going while the condition is true. If the condition is false at the start, the instructions do not run at all. For example, a game might keep accepting moves while the player has lives remaining. If the player starts with no lives, it should not accept a move.

A REPEAT...UNTIL loop checks its condition after running the instructions. It always runs at least once and stops when the condition becomes true. For example, a program can ask for a password, then repeat the request until the correct password is entered: it needs to make the first request before it can check the answer.

Common exam mistake: WHILE and REPEAT...UNTIL usually describe opposite sides of the stopping test. โ€œWHILE the password is incorrectโ€ means keep going while that is true; โ€œUNTIL the password is correctโ€ means stop when that becomes true. Also check whether the instructions need to run at least once before choosing REPEAT...UNTIL.

Related resources

Keep learning with resources for this subject.

Computer Science

Explore

Computer Science

View subject overview

Question bank

Practice exam-style questions

Revision guides

Review key concepts

Was this answer helpful?

Was this answer helpful?

Add as a preferred source on Google

Related student questions

1 Cell biology

Active Transport vs Diffusion: What Is the Difference?

Learn what active transport is, why it needs energy, and how it differs from diffusion in GCSE Biology, with clear definitions and examples.

Read the answer โ†’

1 Cell biology

How Does Mitosis Work in the Cell Cycle?

Learn how mitosis fits into the cell cycle, from cell growth and DNA replication to chromosome separation and two genetically identical cells.

Read the answer โ†’

1 Cell biology

Eukaryotic vs Prokaryotic Cells

Learn the differences between eukaryotic and prokaryotic cells, including their nuclei, genetic material, plasmids and sub-cellular structures.

Read the answer โ†’

1 Cell biology

What Is Diffusion? GCSE Biology Explained

Learn what diffusion means in GCSE AQA Biology, how concentration affects net movement, examples in living organisms, and common exam mistakes.

Read the answer โ†’

1m+ Students Can't Be Wrong

What GCSE and A-level students say after revising with MathsGenie.

Harvey B. avatar

Harvey B.

Student

โ€œThis is such an amazing platform, it offers everything needed to improve your grade in a time efficient manor. Personally I love the videos as I am able to find areas that I am weak at in the practice papers.โ€
Tameem R. avatar

Tameem R.

Student

โ€œGenuinely took me from a grade 4 in maths to achieving a grade 8 in my GCSE's in less than a few months. Best mathematics revision website for those who are aiming to get those high grades.โ€
Anyim P. avatar

Anyim P.

Student

โ€œGenuinely I think every maths student should have this site. It takes you through the entire AS and A level Maths course, alongside exam questions with step by step solutions.โ€
Muhammad A. avatar

Muhammad A.

Student

โ€œpredicted papers are very useful and i believe there's not a better website for GCSE maths in the UKโ€
Rayan K. avatar

Rayan K.

Student

โ€œBest Maths Resource out there! Absolutely amazing videos and very concise explantions on everything. Don't even get me started on the loads of exam question/worksheets that are so helpful. And it's all free!โ€
Dee avatar

Dee

Student

โ€œThe best Maths resource site in the world! They have it all and do a great job of keeping everything up to date. I still don't know how they are able to make this free for all. You are truly amazing.โ€
Hamid I. avatar

Hamid I.

Student

โ€œThey have helped me with my A level Maths performance significantly and I jumped from a grade U to a Grade A in only 2-3 months. I HIGHLY recommend to Maths students especially for A level.โ€
Sophie avatar

Sophie

Student

โ€œMathsGenie's YouTube videos and worksheets are amazing. The videos go into such great depth but in a way that's simple to understand.โ€
Maria E. avatar

Maria E.

Student

โ€œAmazing website! Truly helped with my GCSEs - I was a very poor student. Managed to go up and reach all grade 6-9's from U-4's. Would definitely recommend :)โ€
Justine K. avatar

Justine K.

Student

โ€œAbsolutely brilliant website with well organised, well written resources for learning or revising maths. I never hesitate to recommend mathsgenie to my students.โ€
Daryl G. avatar

Daryl G.

Student

โ€œTook me a bit of getting used to but this new site is excellent. I found the old one really useful but this is next level. I share it with all my colleagues and students.โ€
Binuk J. avatar

Binuk J.

Student

โ€œI used to be really bad at math. My first GCSE mocks I had a 2 but after I found MathsGenie I jumped from 2 to 4 under 3 months.โ€
Jourdie avatar

Jourdie

Student

โ€œImproved my grade, I used to be borderline passing maths now I'm performing much better. There are videos, practice papers, solutions, exam questions, past GCSE papers all for free. This is really useful.โ€
Olla avatar

Olla

Student

โ€œHonestly, it's super great. Easy, with the explanation on the side. Every topic also has more than 50 questions, making you feel more confident in doing different types f question in one topic. Try it!โ€

Ready to breeze through your GCSEs?IGCSEs?A-Levels?AS Levels?GCSEs?GCSEs?

Sign inStart studying for free

Footer

Quick links

  • GCSE past papers
  • GCSE question bank
  • GCSE worksheets
  • GCSE revision guides
  • GCSE lessons
  • Literary Hub
  • Free maths course
  • A Level past papers
  • A Level question bank
  • Old MathsGenie

Tools

  • Revision planner
  • Mock exam builder
  • Ask Genie AI
  • Answer marking
  • Grade calculator
  • Pricing

Company

  • About MathsGenie
  • Careers
  • Contact
  • For educators
  • For parents
  • Student ambassadors
  • Help centre
  • More resources
  • Blog
  • Student questions
  • Sitemap
  • Privacy policy
  • Terms of Service
  • Cookie policy
  • Report a bug

GCSE

  • Biology
  • Chemistry
  • English Language
  • English Literature
  • Geography
  • Maths
  • Old Maths
  • Physics
  • Statistics

IGCSE

  • Biology
  • Business
  • Chemistry
  • Computer Science
  • English Language
  • English Literature
  • Geography
  • Maths
  • Physics

A Level

  • Biology
  • Business
  • Chemistry
  • Economics
  • Maths
  • Old Maths
  • Physics
  • Psychology
  • Sociology

AS Level

  • Biology
  • Business
  • Chemistry
  • Economics
  • Maths
  • Physics
  • Psychology
  • Religious Studies
  • Sociology
MathsGenie logo

ยฉ 2026 MyDojo, Inc. All rights reserved. MyDojo, Inc. does business as MathsGenie.

Exam board names are used for identification only and do not imply affiliation or endorsement.