Easy to remember is that in
SharpBASIC all program flow is placed within
do .. end blocks, be it in the main section directly, with control flow statements or in subroutines or functions.
The counterpart of the
do .. end block is the
is .. end block. Only declarations and definitions can occur within an
is .. end block. Easy to remember is that
is .. end blocks always precede
do .. end blocks, be it in the prologue section before the main
do .. end block, or before the
do .. end block of a subroutine or function to declare local variables. The one exception to this rule is the
let..on..is-statement.
SharpBASIC is quite flexible if it comes to
is .. end blocks. They can be used with virtually any declaration to make life easier for the programmer. For example, instead of repeatedly using the
dim statement:
Code: Select all
dim is
x, z: int = 1; ' x and z initialized as 1
y: int;
' ...
end
The same code structure can also be used with
decl and
const declarations. Note that
is .. end blocks can be used in combination with the
global and
extern directives too. If we would want to declare
x and
y as global to make them accessible in other modules, we could write:
Code: Select all
global dim is
x, z: int = 1;
y: int;
' ...
end
or, to enclose more than just the
dim declarations:
Code: Select all
global is
decl is
func Times2(value: int): int;
' ...
end
const is
msg = "Hello, World!"
' ...
end
dim is
x, z: int = 1;
y: int;
' ...
end
end