Topic : The GFA-Basic Compendium Author : GFA Systemtechnik GmbH Version : GFABasic.HYP v2.98 (12/31/2023) Subject : Documentation/Programming Nodes : 899 Index Size : 28056 HCP-Version : 3 Compiled on : Atari @charset : atarist @lang : @default : Document not found @help : Help @options : +g -i -s +z @width : 75 @hostname : STRNGSRV @hostname : CAB @hostname : HIGHWIRE @hostname : THING View Ref-FileSELECT x CASE y [TO z] or CASE y [,z, ...] (instructions) CONT CASE TO y (instructions) CASE y TO (instructions) DEFAULT (instructions) ENDSELECT x, y, z: iexp or string-constant with a maximum length of 4 characters The command SELECT makes branching possible using the CASE command, on the basis of the value of the numerical expression x. The following examples give an explanation of the program structure that results: x=0 SELECT x+2 CASE 1 PRINT "x is equal to 1" CASE 2 TO 4 PRINT "x is equal to 2, 3, or 4" CASE 5,6 PRINT "x is equal to 5 or 6" DEFAULT PRINT "x is not equal to 1, 2, 3, 4, 5, or 6" ENDSELECT --> The message 'x is equal to 2, 3, or 4' is displayed. First the numerical expression after SELECT is evaluated, which is the branch condition, in this case 2. Then the various CASE instructions are gone through and checked as to whether the current value of the branch condition is to be found. In this example the argument '1' follows the first CASE command. Since the branch condition is 2, the program jumps to the next CASE. After the second CASE are the arguments '2 TO 4'. As the value of x falls within this range the condition is fulfilled and the message printed on the screen. After that, program execution continues after the command ENDSELECT. After the third CASE command is a further variant of the possible arguments for the SELECT command. There the desired values are separated, in a list, by commas. If none of the current branch criterion after the various CASE commands is met, then the instructions between DEFAULT and ENDSELECT are executed (assuming a DEFAULT is present). In addition, instead of DEFAULT, OTHERWISE can be used (giving compatibility with other BASICs) but the GFA interpreter replaces it with DEFAULT automatically. Also, after CASE commands, not only numeric values but also strings may be used as the argument. These may have a maximum length of four characters. If only one character is specified then its ASCII value is used as the branch criterion. If two characters are specified, then this value is calculated as follows: ASCII value of first character + 255 * ASCII value the second character. ...and so on for the third and fourth characters. Note: The maximum length of CASE is 4 characters, i.e. CASE "ABCD". Example: exit!=FALSE REPEAT key%=INP(2) SELECT key% CASE "a" TO "z" PRINT "the lower-case letter "+CHR$(key%)+" was entered" CASE "A" TO "Z" PRINT "the upper-case letter "+CHR$(key%) +" was entered" CASE 27 exit!=TRUE !program ends when <Esc> key is pressed DEFAULT PRINT "an inadmissible key was pressed!" ENDSELECT UNTIL exit! --> Within a loop the keyboard is queried and the program jumps according to which key was pressed and the appropriate message is displayed. Pressing the Esc key is used as an abort criterion for the loop. The next example illustrates the meaning of the CONT command, which is effective if it comes before a CASE or DEFAULT command. This CONT command must not be confused with the command of the same name used for resuming execution of an interrupted program run. Example: x=1 SELECT x CASE 1 PRINT "x is equal to 1" CONT CASE 2 PRINT "x is equal to 2" CASE 1,3 PRINT "x is equal to 3" DEFAULT PRINT "x is not equal to 1, 2, or 3" ENDSELECT --> Displays 'x is equal to 1' and then 'x is equal to 2'. The CONT command provides a method of jumping over a CASE or DEFAULT command. In this example the value x is equal to the argument after the first CASE, i.e. x=1. Therefore the message "x is equal to 1" is printed. Then comes the CONT command, which jumps over the line CASE 2 and, although the branch condition is not fulfilled, the CONT command causes the instruction PRINT "x being equal to 2" to be implemented. The normal processing continues with processing jumping to the ENDSELECT command. Example: SELECT INP(2) CASE "a" TO "g" PRINT "a to g" DEFAULT PRINT "default" ENDSELECT --> If you press one of the a, b, c, d, e, f, or g keys the text 'a to g' is displayed, with any other key (except the shift keys) the message 'default' is printed. With the CASE command a number of different possibilities can be combined, it is not necessary for them to be written separately: SELECT a$ CASE "a" TO "z" CONT CASE "A" TO "Z" CONT CASE "ae","oe","ue","ss","Ae","Oe","Ue" PRINT "OK" ENDSELECT and similarly with ranges: SELECT a$ CASE "a" TO "z","A" TO "Z","ae","oe","ue",... ... ... Memo: For compiler options see sections 'SELECT-CASE Parameter' and 'SELECT-CASE Optimization'. The editor will accept this CASE """" however moving the cursor over the line will cause strange behavior. CONT must proceed a CASE or DEFAULT command or it will not work at all. Even a comment between them will cause it to fail. The editor will allow this: SELECT x PRINT !code placed here won't be executed (dead code) CASE 1 CASE 2 ENDSELECT SELECT x DEFAULT !default is always executed PRINT "hello" ENDSELECT