ProceduralOCR J277
DashboardCoursePracticeReviewProgressGlossary
Saved on this deviceContinue learning

Procedural · OCR J277 programming practice

Progress stays in this browser unless you export it.

Course/Variables/Updating variables
J277 · 2.2.1

Unit 2 · Lesson 2

Updating variables

Lesson progress0 / 7

Build the idea

Start with the concept and its key vocabulary.

Key idea

Update a variable using its current value in a new assignment.

A variable can be assigned a new value. score = score + 1 reads the old score, adds one, then stores the result back in score. Sequence matters because each line sees the value left by the line before it.

Update

Assigning a new value to a variable that already exists.

Increment

Increasing a stored number, often by one.

Sequence

Instructions carried out in order from top to bottom.

Keep these in mind

  • The right side is calculated before the assignment happens.
  • score = score + 1 increases score by one.
  • Each update replaces the previous stored value.

Learning objective

Update a variable using its current value in a new assignment.

Exam tip

Trace updates one line at a time. Write the new value after every assignment instead of trying to calculate the whole program at once.

Common mistake

score =+ 1 does not increment score; it replaces the value with positive 1. score + 1 calculates a value but never stores it.

PreviousNext