Hotspots: Admin Pages | Turn-in Site |
Current Links: Cases Final Project Summer 2007
Discussion 4 - Vishal Patel
Summer 2001 Midterm Review
| anArray aString |
anArray := #('abc' 'def' 'ghi','jkl').
aString := ''.
anArray do: [:each |
aString := aString, each.].
Transcript show: aString.
Because this loop takes each element in the array an and concatinates it to aString which is '' the Transcript will show: 'abcdefghi,jkl' (without the quotes of course).
- What appears on the Transcript ?
The body of the loop gets executed a total of 5 times; 1 for 'abc, 2 for 'def', 3 for 'ghi', 4 for ',', and finally 5 for 'jkl'.
- How many times did the body of the do: loop get executed?
| i test |
i := 1.
test := (i < 10).
[test] whileTrue: [Transcript show: 'hello'.
i := i + 1.].
This will print the hello infinitly becuase test was intialized as true and it never gets checks to see if i 10. This is like writing [true] whileTrue:[...].
- How many times does hello get printed in this example?
Links to this Page
- Vishal Patel last edited on 9 December 2005 at 12:24 am by legolas.cc.gatech.edu
- Fall 2005 Discussion 4 last edited on 6 December 2005 at 3:45 pm by r36h51.res.gatech.edu