. .


ST 4U 201: Using the Case Statement

March 2, 2012 11:09:21.915

Today's Smalltalk 4 You looks at using our simple case statement class from last time. If you have trouble viewing it here in the browser, you can also navigate directly to YouTube. To watch now, click on the image below:

case statement.

If you have trouble viewing that directly, you can click here to download the video directly. If you need the video in a Windows Media format, then download that here.

You can also watch it on YouTube:

Today we'll make use of the case statement code we built last time. Here's the workspace we'll use:

dict := Dictionary new.
dict at: 1 put: [Transcript show: 'This is One'].
dict at: 2 put: [Transcript show: 'This is Two'].

case := CaseStatement new.
case addAll: dict.
case caseAt: 1.
case caseAt: 2.
case caseAt: 3.

case removeCase: 2.
case caseAt: 2.

That creates a simple case statement with two cases (and at the end, removes one of them). Try the first three lines after defining the dictionary and adding it to the CaseStatement - you should see this in the Transcript:

Case Statement

Now execute the removal, and try the last line:

Case Statement

After removing the second case, we get the default case when trying it (as expected). That's it - we now have a working Case Statement object in Smalltalk. Next time you run into someone asking about one, you'll have it

Need more help? There's a screencast for other topics like this which you may want to watch. Questions? Try the "Chat with James" Google gadget over in the sidebar.

Technorati Tags: , ,

[st4u201-iPhone.m4v ( Size: 3579475 )]

posted by James Robertson

 Share Tweet This