View this PageEdit this PageAttachments to this PageHistory of this PageHomeRecent ChangesSearch the SwikiHelp Guide
Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007

Joaquin Estrada - Discussion 4

For the Midterm #1 Review - Spring 2004 problem "Reading Code" -

| anArray aString |
anArray := #('abc' 'def' 'ghi','jkl'). "There shouldn't be a comma here."
aString := ''.
anArray do: [:each |
aString := aString, each.].
Transcript show: aString.

| i test |
i := 1.
test := (i 10).
[test] whileTrue: [Transcript show: 'hello'.
i := i + 1.].

Q1. What appears on the Transcript?
Q2. How many times did the do: loop get executed?
Q3. How many times does hello get printed in this example?


A1. abcdefghi,jkl - because there are four strings: 'abc', 'def', 'ghi', and 'jkl'
and one character: ,
Basically, anything that's not a string or a white space will get parsed
A2. The loop was executed five times because of the four strings and one character.
A3. 'Hello' gets printed infinitely many times because the test variable is a control evaluation inside of a block instead of a block statement.

Link to this Page