# Why the variable "a" is different out of the loop when codes are executed as a whole or by two steps?

3 messages
Open this post in threaded view
|

## Why the variable "a" is different out of the loop when codes are executed as a whole or by two steps?

 Hello, friends. This problem which confuses me comes from a  question I asked in "Squeak - Beginners" days ago.   These are some special integers: myArray := #(2 32 44 67 89 111 123) These special integers need to be specially labelled from integer 1 to 130. The rest normal numbers which myArray doesn't include will be printed also. Here's the code: *|a n myArray| myArray := #(2 32 44 67 89 111 123). n := 1. a := myArray at: n. 1 to: 130 do: [:i|         i = a         ifTrue: [              Transcript show: ('Special number:  i = {1}, a = {2}' format: {i. a}).                  Transcript cr.                 n := n + 1.                     n = 8                    ifTrue: [a := 'I am no longer a number'.]                    ifFalse: [a := myArray at: n. ].                       ]           ifFalse: [                    Transcript show: ('i = {1}, a = {2}' format: {i. a}).                    Transcript  cr.                       ].         ]. Transcript show: a; cr.     'Last line' * Now comes something that makes my head big. If I choose everything and do them, the last line, which should tell me what a is when program jumps out of the loop, exactly shows that a is "I am no longer a number". However, if I choose everything except the last line, and do them. After that, I do the last line. The output is nil. Why is a nil ?   Why's that?   In order to make my question explicit, I recorded a video: https://www.youtube.com/watch?v=pUQAEO4uSpk----- Dig, dig where you are, Down below's well. Let those that walk in darkness shout, Down below's hell. -- Sent from: http://forum.world.st/Squeak-Beginners-f107673.html_______________________________________________ Beginners mailing list [hidden email] http://lists.squeakfoundation.org/mailman/listinfo/beginners Dig, dig where you are, Down below's well. Let those that walk in darkness shout, Down below's hell.