BBC BASIC for Windows
Programming >> BBC BASIC language >> Syntax error???
http://bb4w.conforums.com/index.cgi?board=language&action=display&num=1365080729

Syntax error???
Post by coolguy on Apr 4th, 2013, 1:05pm

Hello all,

I have used the following code but am not sure where I have gone wrong, the error keeps coming up with Syntax error. My aim is to allow the user to try the program again if they don't choose from the dice given.

Code:

INPUT "Choose which dice to throw, 4, 6 or 12." Choice%
CASE Choice% OF
WHEN 4 PRINT "4 sided dice thrown, score "; Dice1
WHEN 6 PRINT "6 sided dice thrown, score ";Dice2
WHEN 12 PRINT "12 sided dice thrown, score ";Dice3
WHEN <> 4 OR 6 OR 12 PRINT "ERROR"
ENDCASE

Re: Syntax error???
Post by admin on Apr 4th, 2013, 9:17pm

on Apr 4th, 2013, 1:05pm, coolguy wrote:
I have used the following code but am not sure where I have gone wrong, the error keeps coming up with Syntax error.

You need to replace the last of your cases with an OTHERWISE clause:

Code:
        INPUT "Choose which dice to throw, 4, 6 or 12." Choice%
        CASE Choice% OF
          WHEN 4 PRINT "4 sided dice thrown, score "; Dice1
          WHEN 6 PRINT "6 sided dice thrown, score ";Dice2
          WHEN 12 PRINT "12 sided dice thrown, score ";Dice3
          OTHERWISE PRINT "ERROR"
        ENDCASE 

Richard.
Re: Syntax error???
Post by coolguy on Apr 5th, 2013, 10:13am

Hi Richard

I was unaware of any such syntax, thank you for clearing it up, works perfectly well now. Thanks a lot.

Regards


Re: Syntax error???
Post by JGHarston on May 13th, 2013, 9:36pm

on Apr 4th, 2013, 1:05pm, coolguy wrote:
CASE Choice% OF
WHEN 4 PRINT "4 sided dice thrown, score "; Dice1
WHEN 6 PRINT "6 sided dice thrown, score "grinice2
WHEN 12 PRINT "12 sided dice thrown, score "grinice3
WHEN <> 4 OR 6 OR 12 PRINT "ERROR"
ENDCASE
The parameters to WHEN are a constant expression, just like any other constant expression. What happens if you do:
PRINT 4
PRINT 6
PRINT <> 4 OR 6 OR 12

Often the simplest way to start debugging a piece of code is to PRINT each of the parameters and see what happens.

on Apr 5th, 2013, 10:13am, coolguy wrote:
I was unaware of any such syntax, thank you for clearing it up, works perfectly well now. Thanks a lot.
Help -> Help topics -> CASE