In a message dated 19/10/2003 14:00:33 GMT Standard Time, [EMAIL PROTECTED] writes:
It seems a wonderful facility. Something like:

WHEN entry=-1
  PRINT"Don't enter negative numbers, mate!"
  RETRY
END WHEN

would potentially be useful, but I don't know how it's meant to work
in SBASIC. I vaguely remember back in the 1980s that very early ROMs
(the first external eproms?) had a keyword called BECOMES, implying a
syntax of something like WHEN var BECOMES <value> I suppose. It's
obviously not in official Sinclair ROMs or anything else modern.

SMSQ/E at least doesn't seem to allow an entry of the example I typed
above - so the syntax is definitely not WHEN var=value or WHEN var in
SBASIC, I've never been able to figure out how it works if it works at
all in SBASIC.

Minerva claims to be able to use it (Laurence...are you there?),
here's some info from the manual:

The Minerva manual lists an example along the lines of the above:

WHEN a=6
PRINT 'a is now six'
END WHEN

Single line WHEN should work, like the equivalent FOR, REPeat, IF etc.

When Variable processing can be turned off with  WHEN a  (that is,
specifying a variable name but no value test), and WHEN anything (i.e.
any name) will turn off all current WHEN processing.

It does not specify how to resume processing from such a WHEN clause,
but presumably once END WHEN is reached, normal execution CONTINUEs?

End of essay :-)
Digging out my SBASIC/SuperBASIC Reference Manual throws some light on the
WHEN condition
statement.... (or at least I tried to work out when and how it worked)
 
Although the structure is provided in JS or later ROMs (including Minerva) and even the THOR XVI, it is not present in SMSQ/e.   It is also highly unreliable unless you have Minerva 1.77 or later (although Toolkit II does improve it slightly).  Problems, unless you have v1.77 Minerva or later:
 
- Block called more than once
- May report bad name when the block is called (ie the condition is true)
- The interpreter allows the WHEN to remain in force despite NEW, CLEAR, LRUN, LOAD, MERGE and MRUN, unless you have Toolkit II.
- JS and THOR XVI only allow a max. 20 WHEN clauses
 
The condition can be anything allowed by an IF statement PROVIDED that it begins with a variable, for example
 
WHEN a-10=b         is fine
WHEN 10-a=b         is not
 
You also have to be careful, as WHEN is not iterative - ie. if the code contained in the WHEN... END WHEN structure alters a variable which sets the condition true again, then the WHEN block is not called a second time.
 
There is also a big problem, in that if the variables used in the condition test are not defined when the interpreter first needs to test the condition - an error in _expression_ is reported - for example:
 
4 WHEN x>1 AND y>1
5 x=x+1:PRINT 'X and Y are greater than 1'
6 END WHEN
10 PRINT "start"
100 FOR x=1 TO 2
110  FOR y=1 TO 2
120     PRINT !x,y!
130 END FOR y
140 END FOR x
 
You get an error in _expression_ when the program reaches line 100 - the interpreter realises that it needs to test x, but does not know what y is.  To solve this, add:
 
1 y=0
 
The other main problem is that if you make up several WHEN clauses, which test the same variable for different conditions, if the conditions overlap, there is no guarantee which WHEN clause will be executed !!
 
As suggested by Dilwyn, if the WHEN clause is executed (condition is true), once END WHEN is reached, the program will continue from where it was before calling the WHEN clause.  There is no way of validly exiting a WHEN clause.
 
--
Rich Mellor
RWAP Services
35 Chantry Croft, Kinsley, Pontefract, West Yorkshire, WF9 5JH
TEL: 01977 610509
Visit our website at:
URL:http://www.rwapsoftware.co.uk

In need of adventure?
URL: http://www.rwapadventures.com


Stuck with ordinary dial up internet connection ??

Read our review of internet accelerators and broadband at:
URL:http://www.rwapservices.co.uk

Reply via email to