Stage 93: Let's jump!

Follow the development of the SharpBASIC compiler and share your thoughts and ideas.
Locked
User avatar
frank
Site Admin
Posts: 40
Joined: Sun Nov 21, 2021 12:04 pm
Location: Netherlands
Contact:

Stage 93: Let's jump!

Post 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.
Last edited by frank on Mon Jun 19, 2023 1:06 pm, edited 8 times in total.
Keep it simple!
Locked