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

CoWeb assignment - 2

Tracing Code (1 point)
1 + 2 * 3 –  Cascade expected ->4 factorial

a := #(1 2 3 4 5)        result-> #(1 2 3 4 5)

a select: [:i | i odd]   result-> #(1 3 5)

b := a                   result-> #(1 2 3 4 5)

a := a reversed          result-> #(5 4 3 2 1)

b collect: [:i | i * i]  result-> #(1 4 9 16 25)

a perform: #at: withArguments: #(4) result-> 2


Message Passing (1 point)

For each part, indicate what is the object, what is the message, and what are the arguments.

while loop

while (aBooleanTest)
{
// do stuff
}

[aBooleanTest] whileTrue: [“do stuff”]

object = [aBooleanTest]
message = whileTrue:
arguments = [“do stuff”]


for loop

for (i = 1; i = 10; i++)
{
// do stuff
}

1 to: 10 do: [:i | “do stuff”]

object = 1
message = to: do:
arguments = 10 and [:i | “do stuff”]

if/then/else

if (aBooleanTest)
{ // do stuff
}
else
{ // do stuff
}

[aBooleanTest] ifTrue: ["do stuff"]
ifFalse:["do stuff"].

object = [aBooleanTest]
message = ifTrue: and ifFalse:
arguments = ["do stuff"] and ["do stuff"]

Link to this Page