Added SWICH/CASE/DEFAULT/ENDSWITCH to docs
This commit is contained in:
parent
e33460d84d
commit
25016018ac
1 changed files with 125 additions and 0 deletions
125
commands.md
125
commands.md
|
|
@ -107,6 +107,17 @@ process("hello",42,myvar)
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## CASE
|
||||||
|
|
||||||
|
Defines a case branch within SWITCH statement.
|
||||||
|
|
||||||
|
**Syntax:**
|
||||||
|
```
|
||||||
|
See SWITCH
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## DEC
|
## DEC
|
||||||
|
|
||||||
Decrements a variable or memory location by 1.
|
Decrements a variable or memory location by 1.
|
||||||
|
|
@ -129,6 +140,17 @@ DECREMENT screenColor
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## DEFAULT
|
||||||
|
|
||||||
|
Defines the default branch in SWITCH statement.
|
||||||
|
|
||||||
|
**Syntax:**
|
||||||
|
```
|
||||||
|
See SWITCH
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## ELSE
|
## ELSE
|
||||||
|
|
||||||
Alternative branch in IF statement.
|
Alternative branch in IF statement.
|
||||||
|
|
@ -151,6 +173,17 @@ See IF
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## ENDSWITCH
|
||||||
|
|
||||||
|
Terminates SWITCH block.
|
||||||
|
|
||||||
|
**Syntax:**
|
||||||
|
```
|
||||||
|
See SWITCH
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## FEND
|
## FEND
|
||||||
|
|
||||||
Ends a function definition.
|
Ends a function definition.
|
||||||
|
|
@ -561,6 +594,98 @@ remaining = total - used
|
||||||
|
|
||||||
---
|
---
|
||||||
|
|
||||||
|
## SWITCH
|
||||||
|
|
||||||
|
Multi-way branching based on variable value comparison.
|
||||||
|
|
||||||
|
Features implicit breaks (automatic jump to ENDSWITCH after each case), supports nesting, and works with BYTE and WORD types.
|
||||||
|
|
||||||
|
**Syntax:**
|
||||||
|
```
|
||||||
|
SWITCH <variable>
|
||||||
|
CASE <value>
|
||||||
|
[statements]
|
||||||
|
[CASE <value>
|
||||||
|
[statements]]
|
||||||
|
[DEFAULT
|
||||||
|
[statements]]
|
||||||
|
ENDSWITCH
|
||||||
|
```
|
||||||
|
|
||||||
|
**Notes:**
|
||||||
|
- Each CASE automatically breaks (jumps to ENDSWITCH) after execution
|
||||||
|
- CASE values can be literals, constants, or variables
|
||||||
|
- DEFAULT branch is optional and executes when no CASE matches
|
||||||
|
- DEFAULT must come after all CASE statements
|
||||||
|
- Only one DEFAULT per SWITCH
|
||||||
|
- BYTE variables can only be compared with values 0-255
|
||||||
|
- Can use `#PRAGMA _P_USE_LONG_JUMP 1` for large switch statements
|
||||||
|
- Nested SWITCH statements are supported
|
||||||
|
|
||||||
|
**Examples:**
|
||||||
|
```
|
||||||
|
// Basic switch with default
|
||||||
|
SWITCH status
|
||||||
|
CASE 1
|
||||||
|
result = 10
|
||||||
|
CASE 2
|
||||||
|
result = 20
|
||||||
|
DEFAULT
|
||||||
|
result = 0
|
||||||
|
ENDSWITCH
|
||||||
|
|
||||||
|
// Switch with constants
|
||||||
|
BYTE CONST MAX = 100
|
||||||
|
SWITCH value
|
||||||
|
CASE MAX
|
||||||
|
overflow = 1
|
||||||
|
CASE 50
|
||||||
|
halfway = 1
|
||||||
|
ENDSWITCH
|
||||||
|
|
||||||
|
// WORD switch
|
||||||
|
WORD big_val
|
||||||
|
SWITCH big_val
|
||||||
|
CASE 1000
|
||||||
|
mode = 1
|
||||||
|
CASE 5000
|
||||||
|
mode = 2
|
||||||
|
DEFAULT
|
||||||
|
mode = 0
|
||||||
|
ENDSWITCH
|
||||||
|
|
||||||
|
// Nested switch
|
||||||
|
SWITCH outer
|
||||||
|
CASE 1
|
||||||
|
result = 1
|
||||||
|
CASE 2
|
||||||
|
SWITCH inner
|
||||||
|
CASE 10
|
||||||
|
result = 20
|
||||||
|
CASE 20
|
||||||
|
result = 40
|
||||||
|
ENDSWITCH
|
||||||
|
DEFAULT
|
||||||
|
result = 0
|
||||||
|
ENDSWITCH
|
||||||
|
|
||||||
|
// Using variables in CASE
|
||||||
|
BYTE threshold1
|
||||||
|
BYTE threshold2
|
||||||
|
LET threshold1 = 50
|
||||||
|
LET threshold2 = 100
|
||||||
|
SWITCH temperature
|
||||||
|
CASE threshold1
|
||||||
|
fan_speed = 1
|
||||||
|
CASE threshold2
|
||||||
|
fan_speed = 2
|
||||||
|
DEFAULT
|
||||||
|
fan_speed = 0
|
||||||
|
ENDSWITCH
|
||||||
|
```
|
||||||
|
|
||||||
|
---
|
||||||
|
|
||||||
## WEND
|
## WEND
|
||||||
|
|
||||||
Terminates WHILE loop.
|
Terminates WHILE loop.
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue