levo

Program Control Structures

Methods and passing control between them

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

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.

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.