Page 1 of 1

Stage 93: Let's jump!

Posted: Sun Feb 20, 2022 2:39 pm
by frank
SharpBASIC supports jump statements, which would be equivalent to BASIC's goto. However, in SharpBASIC the keyword for this statement is jump. The statement allows for an immediate jump to a label, but only inside subroutines or functions. Labels start with the symbol @ immediately followed by the label's identifier.

The following example jumps out of a loop-statement:

Code: Select all

sub sub1()
  dim n:int = 0;
do
  loop do
    if n == 6 do
      jump @here;
    end
    n = n + 1;
  end
  @here;
  print(n);
end
The following example jumps out of three for-statements:

Code: Select all

sub sub1()
  dim i, j, k: itr;
do
  for i = 1 to 9 :++ do
    for j = 1 to 5 :++ do
      for k = 1 to 3 :++ do
        if i == 6 do
          jump @thend;
        end
      end
    end
  end
  @thend;
  print(i);
end
As of stage 93, the keyword end is considered a compound statement terminator and no longer requires an additional semicolon.