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

Sp2002 Midterm Review: Reading Code

Back to Spring 2002 Midterm Review


Transcript will show 'abcdefghi,jkl'.
Meaning the do loop was executed 5 times.

The last piece of code is bad. If I am correct, since the i:= i+1 is inside a block of code, that i is local to that block of code. Meaning that the i that the (i<10) uses never gets incremented. This throws the code into an infinite loop.

Randy Rockinson
Blocks can access variables in their enclosing method – happens all the time. (Try it!) Mark Guzdial

test := (i < 10).
[test] whileTrue: ...

The issue with this code is the fact that test is evaluated to a boolean on the line above the whileTrue statement. Afterwards, the value of test will not change.

This is essentially the same reason that (i < 10) whileTrue: [...] doesn't make sense and is not allowed: the (i < 10) will evaluate to a boolean and then that boolean will be sent the whileTrue: message (which will lead to an infinite loop or no execution).

No execution. #whileTrue: is not understood by instances of subclasses of Boolean, but rather by BlockContexts. It's a little more complicated than this, but that's a start. [i < 10] whileTrue: [...] is perfectly acceptable Shaggz

Shaggz: Above I indicated that (i < 10) whileTrue: is not allowed: I was merely explaining why the boolean expression needs to be placed in a block (to prevent evaluation).

and i was merely indicating that of the two options (loop or error), you'll get the friendly pinkish debugger every time. =)

D. Hilley
Since the comma is string concatenation, wouldnt the Transcript actually show 'abcdefghijkl'...and the do-loop would only execute 3 times?

String concatenation doesn't count in this case: Look carefully. Nice job, D. Hilley! Mark Guzdial

So the 'ghi','jkl' is actually entered as one object in the collection in the first part?

Shaggz, what are you talking about in the second part? I would guess this evaluates to an infinate loop as well since the block would contain true.


I just messed around with this. Actually 'ghi' , 'jkl' are 3 seperate objects entered. do anArray size. I think it's weird too.

Marco Rogers

Link to this Page