levo

Program Control Structures

Count-controlled repetition with FOR

  • 3 things to know
  • AS Unit 1

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.

What is inside Levo

Six ways to work the same material.

1Closed book
2Open book
3Closed book

The 3-step method, run for you

Answer cold, learn it, then prove it stuck. Levo tracks the jump between your first attempt and your last.

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

Cram a whole paper in one sitting

Sort every topic into what you know and what you do not, then drill only the weak ones.

A null is the of one.
absencepresencetype

Blank Blitz makes facts automatic

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

AA null means no value has been recorded.
BZero and an empty string are values.
CA null is the absence of a value.

Build It gets the exam shape right

Assemble a full-mark answer from its marking points, in the order an examiner wants them.

An error is the mistake a person made.
TrueFalse

Test It catches misconceptions

Spot the fault in a statement. The traps are the mistakes students actually make.

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.

Attempt a question from memory, write the correct version, then attempt it again. Levo records the jump between your first attempt and your last, and brings each question back on the day you are due to forget it.

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