Variable Scope Flashcards

1
Q

When do variables come into scope

A

from when they are first defined

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
2
Q

when do variables lose scope

A

when the statement block they were defined in ends, closing curly bracket

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
3
Q

using a variable after the block it was defined in results in

A

an error ‘cannot be resolved’

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
4
Q

how to keep a variable after a loop or if statement

A

declare the variable beforehadn

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
5
Q

can variables in scope be redefined

A

no

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
6
Q

when do variables defined in initialisation of for loop lose scope

A

when for loop completes

How well did you know this?
1
Not at all
2
3
4
5
Perfectly
7
Q

when do variables inside for loops lose scope

A

at each iteration of the for loop

How well did you know this?
1
Not at all
2
3
4
5
Perfectly