Variable Scope Flashcards
1
Q
When do variables come into scope
A
from when they are first defined
2
Q
when do variables lose scope
A
when the statement block they were defined in ends, closing curly bracket
3
Q
using a variable after the block it was defined in results in
A
an error ‘cannot be resolved’
4
Q
how to keep a variable after a loop or if statement
A
declare the variable beforehadn
5
Q
can variables in scope be redefined
A
no
6
Q
when do variables defined in initialisation of for loop lose scope
A
when for loop completes
7
Q
when do variables inside for loops lose scope
A
at each iteration of the for loop