fall;
See also when
By default, the when statement, which can be considered SharpBASIC's switch statement, does not support implicit fall-through, so the fall statement must be used to force an explicit fall-through to the next branch.
A when statement can exist of multiple is branches, each having one or more conditions. Normally, if a condition of one branch is met, the block following that branch is executed after which the when statement is left. In order to also test the next branch, the fall statement can be included at the end of the execution block.
So the fall statement prevents an early exit of the when statement and forces testing of the next branch. But the next branch or branches are skipped if no further condition is met, except for the default branch, indicated by the keyword other. The example below illustrates this.
A fall statement is not allowed in the default branch. This is because the when statement is always left after the default branch is executed.
' SharpBASIC when with fall-through programming example
' -----------------------------------------------------
option strict;
incl "lib/sys.sbi";
dim n: int = 2;
main do
when n
is 1 do
print("this is one");
fall;
is 2 do
print("this is two");
n = 3;
fall;
is 3 do
print("this is three");
fall;
is 4 do
print("this is four");
fall;
is 5 do
print("this is five");
is other do
print("this is default");
end
end
Output:
this is two
this is three
this is default