levo

Program Control Structures

Methods and passing control between them

  • 3 things to know
  • AS Unit 1

Overview

Return value do, and what does the keyword void, three benefits of dividing a program into methods and method having a single, well-defined purpose.

What you need to know

Answer each one before you reveal it.

Your recallNot started
Key term

What is recursion, and why must a recursive method have a base case?

Key term

What is a method?

Key term

What happens to the flow of control when a method is called?

Questions from this subtopic

Each one with the model answer underneath.

  1. 1

    What is a method?

    Model answer

    A method is a named block of statements that performs one identified task and can be called from elsewhere in the program.

  2. 2

    What happens to the flow of control when a method is called?

    Model answer

    Control transfers from the calling statement to the first statement of the method, the method runs to completion, and control then returns to the point immediately after the call.

  3. 3

    In the call area(4, 7), what are the values 4 and 7 called, and what name is given to the variables that receive them inside the method definition?

    Model answer

    The values 4 and 7 written at the call are the arguments, and the variables named in the method header that receive those values are the parameters.

  4. 4

    What does a return value do, and what does the keyword void mean?

    Model answer

    A return value is the result the method hands back to the caller, and void states that the method hands back no value at all.

  5. 5

    int twice(int n) { return n * 2; } ... int x = twice(5) + twice(3); — what value does x hold?

    Model answer

    The first call returns 10 and the second returns 6, and the two results are then added, so x holds 16.

  6. 6

    Why is a method call described as a sequential step rather than as a jump the programmer has to manage?

    Model answer

    The language records where the call came from and returns there automatically, so from the caller's point of view the whole call is one step in the sequence.

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.