levo

Program Control Structures

Count-controlled repetition with FOR

  • 3 things to know
  • AS Unit 1
Start revising · £5/month

Overview

Repetition as a control structure, unconditional repetition and off-by-one error.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

for (int i = 1; i <= 5; i++) { System.out.print(i + " "); } — what does this fragment print?

Key term

What is repetition as a control structure?

Key term

What is meant by unconditional repetition, and which construct normally implements it?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is repetition as a control structure?

    Model answer

    Repetition is the control structure that causes a block of statements to be executed more than once, either a set number of times or until a condition changes.

  2. 2

    What is meant by unconditional repetition, and which construct normally implements it?

    Model answer

    Unconditional repetition repeats a block a fixed number of times settled before the loop begins rather than by testing the data, and a counted FOR loop normally implements it.

  3. 3

    Which three parts does a Java for header have, and what is the purpose of each?

    Model answer

    A for header holds an initialisation that sets the counter, a condition tested before every pass, and an update applied at the end of each pass.

  4. 4

    for (int i = 1; i <= 5; i++) { System.out.print(i + " "); } — what does this fragment print?

    Model answer

    The counter takes the values 1, 2, 3, 4 and 5 in turn and each is printed, so the output is 1 2 3 4 5; the loop ends when the counter reaches 6 and the condition fails.

  5. 5

    How many times does the body of for (int i = 0; i < 10; i++) execute?

    Model answer

    The body executes ten times, for counter values 0 through to 9 inclusive.

  6. 6

    How many times does the body of for (int i = 1; i < 10; i++) execute?

    Model answer

    The body executes nine times, for counter values 1 through to 9 inclusive.

Other ways to work this

The same content, four other ways.

Everything in your subscription

Runs, plus a mode for every other kind of session.

1Flash
2Imposter
3Fade
4Brain dump

Learn every subtopic in runs of four questions

Facts flash and fade, a wrong word hides in some of them, and a brain dump decides which questions are locked in.

Software and the Development Environment
Defining Data: Types, Variables and Classes
Program Control Structures
Objects, Classes and Data Structures

Cram the night before, weakest topic first

A quick scan finds your weakest topics. Recall each fact you missed three times in a row.

A null is the of one.
absencepresencetype

Blank Blitz consolidates the facts

Rapid timed gap-fills on the terms and numbers you need to recall without thinking.

✓What it iscovered
~Why it happenspartly there
How long it lastsnot there yet

Explain It tests your understanding

Explain a concept in your own words and see which of its points you covered.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The faults are the mistakes students make most often.

721941163128510

Brain Breaks between sessions

Short focus games to reset attention, so the next set lands better than the last.

Every question in Program Control Structures, on a schedule.

Learn it in runs of four questions, each ending on a brain dump against the clock. Every question you lock in comes back the next day, then at longer gaps, each time just before you would forget it.

Or £46 a year, about £3.83 a month. Cancel anytime.