Home
Project Folders
Teacher Resources
Student Resources
How Do I?
Literacy
MWForum
Site Map
Search
Our Team

MWForum Message [Date Index] [Threads] [Authors] [Attachments] [Subscribe]

[Thread Prev] [Thread Next]

To: mwforum@xxxxxxxxxxxxxxxxxx
Subject: When or if
From: "Wendy Petti" <wpetti@xxxxxxxxxxxx>
Date: Tue, 12 Nov 2002 12:22:08 -0500

I will add to Jeff's and Daniel's explanations with an example of a
procedure in which I twice needed to use "when" instead of "if."

I created a typing race game which would display words to be typed,
along with a textbox in which the user would type.  I wanted a timer to
start the moment a user began to type in the empty user textbox, and I
wanted the timer to stop after 2 minutes and then announce the user's
number of words per minute.

I wrote a procedure to turn the timer on and off, and this procedure
would begin as soon as the student clicked a button to display a set of
words.  At first, I tried "if" commands to activate and deactivate the
timer, but since the computer only checked once near the beginning of
the procedure to see if the user textbox was empty (and it always *was*
empty at that point), the timer never became activated.  So then I
turned to "when" instead, like this:

to start.typing
resett
usertextbox, ct
when [not empty? usertextbox] [resett]
when [timer > 1200]
	[announce [Time's up!]
	score
	comment
	stopall]
end

Both of the "when" commands run constantly until the "stopall" command
is reached.

(resett = reset timer
"score" was another simple procedure to calculate the words per minute.
"comment" was another procedure to display a randomly-chosen
congratulatory remark or friendly insult depending on the number of
words typed.)

The one thing I don't understand about these primitives is the use of
brackets. "when" uses two sets of bracketed commands while "if" only
uses one set:

when [timer > 1200] [do-the-next-step]
if timer > 1200 [do-the-next-step]

I find this difference a bit puzzling and confusing.

Wendy Petti


  • Previous by thread: When or if
  • Next by thread: When or if

  • To save an attachment to your computer, PC users should right-click (Mac users, click and hold the mouse button) on the link and then choose 'save target as' from the pop-up menu. A window will then pop up in which you can choose a location for the file.


    © copyright 2001 - 2008