This study notes covers Deep Dive: Scope Example within Variable Scope for GCSE Computer Science. Revise Variable Scope in 3.2 Programming for GCSE Computer Science with 18 exam-style questions and 10 flashcards. This topic appears less often, but it can still be a useful differentiator on mixed-topic papers. It is section 4 of 7 in this topic. Use this study notes to connect the idea to the wider topic before moving on to questions and flashcards.
Deep Dive: Scope Example
global score = 0 // Global - accessible everywhere
function addPoints(points)
local bonus = 10 // Local - only in this function
score = score + points + bonus
endfunction
addPoints(5)
print(score) // Works - score is global
print(bonus) // ERROR - bonus doesn't exist herePractice questions for Variable Scope
Where can a local variable be accessed?
Identify and explain the scope error in this pseudocode: function calculateTotal(price, quantity) local total = price * quantity endfunction calculateTotal(10, 5) output total