S T R U C T O R I Z E R - User Guide
Elements > Jump

The Jump element indicates some kind of explicit exit from a loop, a routine, or the program. It is not actually a means of structured programming, it rather contradicts the ideas of this concept. It can always be avoided (see example below), but may sometimes be a pragmatic and convenient way to formulate algorithms that otherwise would require some complicated workaround with logical variables, additional conditions etc.

Version 3.29-07/-08 introduced a fourth flavour of Jump element: The throw instruction (aka raise instruction). It is used to leave the current algorithmic context in case of a detected problem (an exception) that can not be solved on the current level but might be handled by some higher context with a more general perspective if we pass the necessary information there. If the thrown problem can be solved on a higher level then the execution may be continued on that level, otherwise the program will abort (as if we had used an exit command). This use of an EXIT element is possibly the most justifiable one.

You are not encouraged to use Jump elements, however.

The following types of "jumps" are supported both on execution and code export:

  1. Loop exit: an empty Jump element or a Jump element containing simply the keyword
    leave
    will just prematurely leave the closest surrounding loop, no matter of what kind. (This form is roughly equivalent to the break statement in languages like C, Java etc.) If the Jump element is contained by several nested loops, then an instruction
    leave n
    (n being a positive integer) within the Jump element will exit from the innermost n loops, such that execution continues with the next instruction after the outer one of the left loops.
  2. Routine exit: To leave a routine (the current diagram) immediately, write
    return
    into the Jump element. This can also be used to return a result value. So if the routine is to provide a result then just write an expression describing the result value or its computation after the keyword return, e.g.
    return a * (b + 3).
  3. Program exit. The default keyword
    exit
    allows you immediately to terminate the entire program, even from within a subroutine. An added integer value would be used as exit code, e.g.
    exit 17
  4. Raising of an exception. Since version 3.29-08, an experimental enhancement allows you to model a kind of simplified structured exception handling. In combination with TRY elements you may raise (or throw) a string as exception (error message) that can be caught by the catch section of a dynamically encapsulating TRY element. In order to launch an error you my write:
    throw "Problem with file " + filename

Note: Since release 3.29, the keywords mentioned above (leave, return, exit, throw) may be subject to customization, see Parser Preferences.

Example for a conditioned Jump used to leave a For loop prematurely:

Exit from a For loop

Of course the Jump could easily be avoided by decomposing the For loop into a While loop (green and yellow elements) using both the negated condition of the alternative and the maxIterations limit as (re-)entry condition:

Loop avoiding a leaving jump

Instruction transmutation

If you happened to write a jump statement of one of the supported kinds into a simple Instruction element by mistake, then you don't need to delete the element, insert a Jump element and enter the entire statement again. By clicking the magic wand button Magic wand (transmutation button) (with the Instruction element selected) you may transmute it into a Jump element (with same content). This can also serve as an easy test whether the statement complies with the syntax rules stated above. (Otherwise the transmutation button simply won't work.)