User Tools

Site Tools


fall

Table of Contents

fall

fall through - a statement to indicate that the next is branch of a by statement must be tested

syntax

fall;

See also by

details

By default, the by statement, which is SharpBASIC's switch statement, does not support implicit fall-through, so the fall statement must be used explicitly to force a fall-through to the next branch.

A by 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 by 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 by 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 any. The example below illustrates this.

A fall statement is not allowed in the default branch. This is because the by statement is always left after the default branch is executed.

example

' SharpBASIC 'by' with fall-through programming example
' -----------------------------------------------------
option strict;

incl "lib/sys.sbi";

dim n: int = 2;

main do

  by 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 any do
      print("this is default");
  end

end
Output:

this is two

this is three

this is default

fall.txt · Last modified: 2025/05/23 10:07 by admin