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

Discussion 4 - Daniel Kitchener

| anArray aString |
anArray := #('abc' 'def' 'ghi','jkl').
aString := ''.
anArray do: [:each |
aString := aString, each.].
Transcript show: aString.

a. What appears on the Transcript ?

Explanation: the program iterates through the array of strings, sticking each one on the end of 'aString'
b. How many times did the do: loop get executed?

5 times - one time for each string, but there's also a comma in there, which does something strange

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

c. How many times does hello get printed in this example?
until the computer runs out of memory - test is only set once, before the loop. code that terminates would look like:
| i |
i := 1.
[i 10] whileTrue: [Transcript show: 'hello'.
i := i + 1.].

Link to this Page