Page Contents:
- Conditional Single-Line Structures
- Conditional Block Structures
- Conditional Functions
- References
Conditional Single-Line Structures
- IF...THEN LineIdentifier
Example:
25 PRINT "howdy";SLEEP 0.5IF TRUE THEN 25
- IF...GOTO LineIdentifier
Example:
25 PRINT "howdy";SLEEP 0.5IF TRUE GOTO 25
- IF...THEN SingleStatement
Example:
IF TRUE THEN PRINT "Howdy"
- IF...THEN MultiStatement
Example:
IF TRUE THEN PRINT "Howdy"; : PRINT " There"
- IF...THEN...ELSE SingleStatements
Example:
IF TRUE THEN PRINT "Yup" ELSE PRINT "Nope"
- ON GOTO
Example:
1 v% = VAL( RIGHT$( STR$( INT( TIMER * 10 ) ), 1) ) + 12 ON v% GOTO 10,11,123 GOTO 110 COLOR 15 : PRINT "0 "; : GOTO 2011 COLOR 14 : PRINT "1 "; : GOTO 2012 COLOR 13 : PRINT "2 "; : GOTO 2020 SLEEP 0.001 : GOTO 1
- ON GOSUB
- ON RESTORE
- GOTO "EVAL" Clause
Example:
FUNCTION WhereToGo%(v%)SELECT CASE v%CASE 2 : WhereToGo% = 140CASE 5 : WhereToGo% = 190CASE 9 : WhereToGo% = 250CASE ELSE : WhereToGo% = 300END SELECTEND FUNCTION1 v% = VAL( RIGHT$( STR$( INT( TIMER * 10 ) ), 1) )GOTO EVAL( WhereToGo%(v%) )140 COLOR 15 : PRINT "2 "; : GOTO 300190 COLOR 14 : PRINT "5 "; : GOTO 300250 COLOR 13 : PRINT "9 "; : GOTO 300300 SLEEP 0.001 : GOTO 1
- GOSUB "EVAL" Clause
- RESTORE "EVAL" Clause
Conditional Block Structure
- IF...THEN Block
Example:
1 v% = VAL( RIGHT$( STR$( INT( TIMER * 10 ) ), 1) )IF v% = 0 THEN : COLOR 15 : PRINT "0 ";ELSEIF v% = 1 THEN : COLOR 14 : PRINT "1 ";ELSEIF v% = 2 THEN : COLOR 13 : PRINT "2 ";ELSE : COLOR 12 : PRINT "? ";END IFSLEEP 0.21GOTO 1
- SELECT CASE Block
Example:
1 v% = VAL( RIGHT$( STR$( INT( TIMER * 10 ) ), 1) )SELECT CASE v%CASE 0 : COLOR 15 : PRINT "0 ";CASE 1 : COLOR 14 : PRINT "1 ";CASE 2 : COLOR 13 : PRINT "2 ";CASE ELSE : COLOR 12 : PRINT "? ";END SELECTSLEEP 0.21GOTO 1
- WHILE...WEND
Example:
WHILE i% < 25
i% = i% + 1
PRINT i%
SLEEP 0.1
WEND
END
Alternative Keyword Delimiters:
- DO WHILE...WEND
- WHILE...LOOP
- DO WHILE...LOOP
- DO...LOOP
Example:
DO
i% = i% + 1
PRINT i%
SLEEP 0.1
IF i% = 25 THEN END
LOOP
- DO...LOOP WHILE
Example:
DO
i% = i% + 1
PRINT i%
SLEEP 0.1
LOOP WHILE i% < 25
END
- DO...LOOP UNTIL
Example:
DO
i% = i% + 1
PRINT i%
SLEEP 0.1
LOOP UNTIL i% = 25
END
Conditional Functions
- IFF
Example:
PRINT IFF( TRUE, "Yup", "Nope")
- CHOOSE
Example:
1 v% = VAL( RIGHT$( STR$( INT( TIMER * 10 ) ), 1) ) + 1PRINT CHOOSE( v%, "Zero ", "One ", "Two " );SLEEP 0.21 : GOTO 1
- NVL$
Example:
1 v% = VAL( RIGHT$( STR$( INT( TIMER * 10 ) ), 1) ) + 1PRINT NVL$( CHOOSE( v%,"Zero ","One ","Two " ), "??? " );SLEEP 0.21 : GOTO 1
- MAX
Example:
a% = 5 : b% = 10PRINT MAX( a%, b% )
- MIN
Example:
a% = 5 : b% = 10PRINT MIN( a%, b% )
References:
- The Conditional (computer programming) article on Wikipedia
- Discussion in this post at the "BASIC Programming Language" Facebook group
No comments:
Post a Comment