The switch code structure below:
switch nLine
case 1
sLine = '&s' + 'Easter Sunday'
case 2
sLine = '&s' + 'Ascension'
case 3
sLine = '&s' + 'Whit Sunday'
else
sLine = ''
endswitch
will generate the following compiled code:
0015 CALL b002=$0BI(@nLine|1) //EqualN
0015 IF_002 @b002 jne+0003
0016 CALL sLine=$0AL(&s|Easter Sunday) //Concat
0017 JMP+0012 //ELSE_002
0017 CALL b003=$0BI(@nLine|2) //EqualN
0017 IF_003 @b003 jne+0003
0018 CALL sLine=$0AL(&s|Ascension) //Concat
0019 JMP+0007 //ELSE_003
0019 CALL b004=$0BI(@nLine|3) //EqualN
0019 IF_004 @b004 jne+0003
0020 CALL sLine=$0AL(&s|Whit Sunday) //Concat
0021 JMP+0002 //ELSE_004
0022 MOV sLine=
0023 ENDF_004
0023 ENDF_003
0023 ENDF_002
Note how the switch statement has been replaced by a series of nested IF_xxx instructions. In effect, the compiler has generated the same code as if we had written the macro below:
if nLine == 1
sLine = '&s' + 'Easter Sunday'
else
if nLine == 2
sLine = '&s' + 'Ascension'
else
if nLine == 3
sLine = '&s' + 'Whit Sunday'
else
sLine = ''
endif
endif
endif
This shows that the switch statement is a convenience for the writing, and legibility, of macros, but not a necessity in the definition of the language.
Topic 123100, last updated on 22-Apr-2020