Instructions
208Compiler
© 2013 Conrad Electronic
Case >= 100
b=14
Case <> 25
b=15
Else
b=b+2
End Case
In CompactC the instructions will be continued after a Case instruction until a break comes up
or the switch instruction is left. With BASIC this is different: Here the execution of the commands
will break off after a Case, if the next Case instruction is reached.
4.3.7 Functions
In order to structure a larger program it is separated into several sub-functions.
This not only improves the readability but allows to combine all program instruc-
tions repeatedly appearing in functions. A program does in any case contain the
function "main", which is started in first place. After that other functions can be
called up from main. A simple example:
Sub func1()
' Instructions in function func1
.
.
End Sub
Sub main()
' Function func1 will be called up twice
func1()
func1()
End Sub
Parameter Passing
In order to enable functions to be flexibly used they can be set up parametric. To do this the para-
meters for the function are separated by commas and passed in parenthesis after the function name.
Similar to the variables declaration first the parameter name and then the data type is stated. If no
parameter is passed then the parenthesis will stay empty.
An example:
Sub func1(param1 As Word, param2 As Single)
Msg_WriteHex(param1) ' first parameter output
Msg_WriteFloat(param2) ' second parameter output
End Sub
Similar to local variables passed parameters are only visible within the function itself.
In order to call up function func1 by use of the parameters the parameters for call up should be writ-
ten in the same succession as they have been defined in func1. If the function does not get paramet-
ers the parenthesis will stay empty.