goto

The goto keyword jumps to another ruleflow statement.

Purpose

The goto keyword is a ruleflow statement used to jump to another statement in the ruleflow.

Context

Body of flowtask blocks

Syntax

goto label;

Description

The target statement must be labeled and this label is the one referenced in the goto statement.

You can use a goto statement in a fork or while statement if the following rules are respected:

  • In a fork statement, the goto statement must not jump to a statement that does not belong to one of the fork blocks.

  • In a while statement, the goto statement must not jump to a statement outside the while loop.

Example

flowtask main
{
   body =
   {
      start: if (turn == Constants.Player1) ChooseMovePlayer1;
               else ChooseMovePlayer2;
               CheckMove;
               if (ending) goto end;
               UpdateDistance;
               ExpandObjects;
               DetectConnect4;
               if (ending)  goto end;
               DetectGridFull;
               if (ending)  goto end;
               ChangeTurn;
               goto start;
      end: EndOfGame;
   }
};

The ruleflow consists of a loop implemented with the goto statement goto start, which jumps to the beginning of the flow. The loop can be interrupted under some conditions and this interruption is implemented with the goto statements goto end. The start and end parts are the labels of the first and last ruleflow statements, respectively.