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

Fall2001 Midterm Review: Reading Code

Link back to Fall 2001 Midterm Review

Transcript should show "abcdefghi,jkl". The do: loop gets executed 5 times, one for each string and one for the character ','.

It gets executed infinite times. "test := (i < 10)." just assigns the value 'true' to test, since the item in parentheses will return a boolean value. -Allen Tyner
I missed that "," the first time. I found it interesting that the "," gets evaluated as a symbol though. Jared Parsons

First one)

Gets displayed on teh screen and the loop executes 4 times.

Second one)

This is an infinite loop. ( i 10) is a boolean expression and only gets evaluated once. Therefor test is always true. You could make this print a limited number of times by changing it to [ i 10 ] which would make it a block and thus you can retest it by taking it's value and switing it to [test value ] whileTrue...
Jared Parsons

Like Jared says in the box. Nice one, Allen! Mark Guzdial

If you type in &#lt; your less than signs will show up correctly. -Allen Tyner
Thanks. I didn't even realize they didn't show up Jared Parsons
I executed the code for the first one and got the 'abcdefghi,jkl' does anyone know why the ',' is in the aString, which is shown on the transcript
Robert Schierholz
hmm.. it doesn't really make sense to me why the output would be abcdefghi,jkl. Isn't an array space separated? Thus, the element 'ghi','jkl' should be counted as a single element which just turns out to be the concatenation of 2 strings. Thus the output should be abcdefghijkl and the loop executed 3 times. I know this is wrong, but can someone explain more clearly why? Thanks
Jesse Shieh

My guess is because it is in a explicit array assignment (ie #(element1 element2), methods are not called. Go ahead and create a string foo and then try to make an array be #(foo size), it creates an array of (foo size) not an array with the size of foo in it. The concatenation method then doesn't get called. Stephen Ingram

Good experiment, Stephen! It all has to do with how the #( ) construct is evaluated. That's why it's actually better (more intuitive) to create an array with message sends, e.g., Array with:with:with: Mark Guzdial

Link to this Page