Grade 6 · lesson 4 of 4

Trace a Function Call Separately

Substitute parameters, follow a local loop and return its result.

Download the grade pack

Supplied materials

  • Paper and pencil; an adult may read aloud. No device, account or purchase is needed.

Learn the idea

A function packages instructions so we can use them with different inputs. Parameters receive the values supplied by each call. A local variable is created for that call; it does not inherit a previous call’s final value. State an input contract so the number of loop repetitions is clear.

Define bump(start, step, repeats): set value = start; repeat exactly repeats times: value = value + step; return value. Assume start and step are integers, and repeats is a whole number from 0 through 5. Trace bump(2, 3, 2) and then a separate call bump(5, 1, 0). Zero repeats means return the starting value unchanged.

  1. Write the function and its parameter contract.
  2. Substitute 2, 3 and 2 into the first call.
  3. Trace each repetition and record the returned value.
  4. Start a fresh trace for the second call, including its zero-repeat case.
Worked example

See the method in action

bump(2, 3, 2): value 2 → 5 → 8, return 8. bump(5, 1, 0): value starts at 5, no loop visits occur, return 5. The second call does not start at 8.

Your turn

Check your reasoning

Your answer is temporary and is not saved to an account. Download your current answer before leaving or reloading. Written work on paper or in another app stays in your own file.

What does bump(1, 2, 3) return?

Feedback appears here after you check. This is practice, not a graded school assessment.

See the answer and explanation

7

The trace is 1 → 3 → 5 → 7. The starting 1 plus three additions of 2 gives 7.

Take it further

Change only the repeat input to 0 in bump(1, 2, 0). Expected return: 1. This test confirms that the loop does not perform an extra visit.

Nothing here is saved to an account or sent to a teacher. The answer download includes your current choice and any checked feedback.

Check the subject sources

These LifeStarter passages, scenarios and exercises are authored for this Academy with AI assistance and review. External resources keep their publishers’ terms. A grade label suggests a starting level; it does not establish alignment with your school’s complete requirements.