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

Benoit St-Jean bstjean at yahoo.com
Sat Nov 18 08:45:38 UTC 2017

nil is the sole instance of UndefinedObject.
It's the value assigned by default to every object (more or less but we'll get there when you'll get the basics) when they are created.  In your case, when you execute/inspect the very last line of your workspace, a is uninitialized, hence nil.
You must not see the whole workspace as a "program".  The environment, in a workspace, execute/prints/inspects just what you  *select* and executes/prints/inspects ONLY that! The workspace doesn't care what you executed before!  All it cares about evaluating is the portion of code that you highlight.

Benoît St-Jean 
Yahoo! Messenger: bstjean 
Twitter: @BenLeChialeux 
Pinterest: benoitstjean 
Instagram: Chef_Benito
IRC: lamneth 
Blogue: endormitoire.wordpress.com 
"A standpoint is an intellectual horizon of radius zero".  (A. Einstein)

      From: RedTigerFish <chihuyu at gmail.com>
 To: beginners at lists.squeakfoundation.org 
 Sent: Saturday, November 18, 2017 2:36 AM
 Subject: [Newbies] 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:


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
Beginners at lists.squeakfoundation.org

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.squeakfoundation.org/pipermail/beginners/attachments/20171118/b986b66c/attachment.html>

More information about the Beginners mailing list