[MWForum]Re: When or if

Mike Sandy mwforum@lists.mathcats.com
Wed, 13 Nov 2002 10:31:26 -0000


Wendy wrote:
....
  a) Using "if" with a "forever" command (or a button set to "many times")
      makes sense when you want the "if" command to be  implemented
      endlessly as long as the condition is true.
b) Using "when" makes sense when you want the condition to be
    constantly evaluated but implemented only once when the condition is
finally met.
....

To show under what conditions WHEN and IF operate
(IF with FOREVER)
try:


to aa
 cg lt 90 st
 pu
 when [colorunder = 0]
      [ rt 90 pd fd 50 pu bk 50  lt 90]
 forever[fd 1 wait 0.01]
end

then use wait 0

Now run

to bb
cg lt 90 st
pu
forever[if  colorunder = 0
[ rt 90 pd fd 50 pu bk 50 lt 90]]
forever[fd 1 wait 0.01]
end

Different processing speeds!

So the conditions under which WHEN and IF (with FOREVER) should
be used will depend on the situation.

Mike