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

Sp2001 Midterm Review: Reading Code

Can you read the code?

a. My original answer was abcdefghijkl
However when I ran the code in squeak it returned abcdefghi,jkl
I don't understand how " , " was considered to be an a string object.

b. Original answer was 4 but I'm guessing it has to run 5 times to include the " , " into the string.

c. Once
Bharath Hemachandran
Try sending inspect to the object and see what you get. Mark Guzdial

a) The "," gets printed out because of the fact that there is no space between 'ghi','jkl'. I assume that when creating an array the delimiter is a blank space (to separate tokens), so since there isn't a blank present (and also since the two inner ''don't get recognized because of the two outer ''), the "," is a part of that one string.

c) When i ran the code Hello printed out an infinite number of times.


a. There are 5 elements in the array: 'abc' 'def' 'ghi' , 'jkl' with comma being one of the elements.

b. 5 times - 5 elements in the array

c. Infinite number of times because the i variable in the block is different from the outside i. Therefore, the loop condition is always true.

Dmitri
I think that it has nothing to do with variable scope... test is defined as true because that is the result of the expression (i 10) on the first (and only) time it is evaluated.

Andrew Harp

no. whileTrue re-evaluates the loop condition everytime. but because the i in the block is different from the outside i, the expression is always true.

Dmitri



Link to this Page