top of page
Search

Goto statement

  • Writer: Ivaylo Fiziev
    Ivaylo Fiziev
  • 4 days ago
  • 2 min read

ree

The unconditional jump instruction is here. It is strange to announce such a trivial thing but it was a real challenge to implement. What makes it hard? It is intended to work on a flattened program tree. Flattening the program tree is the actual problem. In version 2512 we have it working with some limitations.

But lets start with a short introduction.

'Goto' is a statement that is often avoided since it tends to make the code unreadable/unmaintainable if overused. Typical usage is: you do a check and then jump to a specific statement, skipping all statements in between. How do you identify the target statement for the jump? It has a label. The label is just a unique identifier preceding the actual statement. It is actually part of the statement itself. Such statements are known as labelled statements.

Example:

	MyLabel: #i := #i + 1;
	...
	GOTO MyLabel;

You can only jump to labelled statements within the current block. Labels should be unique within the block. As a general rule you cannot jump into a for/while/repeat loop or an if/case statement. You can freely jump outside a for/while/repeat loop or an if/case statement. You can freely jump back and forth as long as the above limitations do not take place.

The labelled statement and all statements after it will be executed after the jump.

This makes it very easy to create an endless loop like in the example above. Be careful with the usage! If you are unsure always use the debugger since it can break the loop and return control to Process Simulate. The same is true for any other loop.

The SCL editor provides some help when working with the GOTO statement.

It auto completes the available label identifiers. Also validates them by checking for duplicated or invalid ones.

Happy jumping :)

 
 
 

Comments

Rated 0 out of 5 stars.
No ratings yet

Add a rating

Subscribe Form

Thanks for submitting!

bottom of page