Jump anywhere: Difference between revisions
Content added Content deleted
(Jump anywhere en Yabasic) |
(Added XPL0 example.) |
||
Line 2: | Line 2: | ||
[[Imperative programming|Imperative programs]] like to jump around, but some languages restrict these jumps. Many structured languages restrict their [[conditional structures]] and [[loops]] to ''local jumps'' within a function. Some assembly languages limit certain jumps or branches to a small range. |
[[Imperative programming|Imperative programs]] like to jump around, but some languages restrict these jumps. Many structured languages restrict their [[conditional structures]] and [[loops]] to ''local jumps'' within a function. Some assembly languages limit certain jumps or branches to a small range. |
||
This task is demonstrate a local jump and a global jump and the various other types of jumps that the language supports. |
This task is to demonstrate a local jump and a global jump and the various other types of jumps that the language supports. |
||
For the purpose of this task, the jumps need not be used for a single purpose and you have the freedom to use these jumps for different purposes. |
For the purpose of this task, the jumps need not be used for a single purpose and you have the freedom to use these jumps for different purposes. |
||
You may also defer to more specific tasks, like [[Exceptions]] or [[Generator]]. |
You may also defer to more specific tasks, like [[Exceptions]] or [[Generator]]. |
||
Line 2,887: | Line 2,887: | ||
[./jump line 17] in new(_) block argument |
[./jump line 17] in new(_) block argument |
||
</pre> |
</pre> |
||
=={{header|XPL0}}== |
|||
XPL0 has no goto statement. The closest statements are 'return' 'exit' |
|||
and 'quit', the latter being used to jump out of a 'loop' from anywhere. |
|||
The 'return' command is implied at the end of a procedure, but when |
|||
explicitly written, it returns to the caller from anywhere (and from a |
|||
function it returns a value). |
|||
Of course there are implied jumps in 'if' statements and in all the |
|||
looping statements. |
|||
An unusual feature is the Restart intrinsic. This is like the 'exit' |
|||
statement, but it restarts the program. It's sometimes simpler to restart |
|||
than to unwind nested procedure calls, if for instance an error is |
|||
detected. |
|||
Certain errors, such as divide-by-zero, can cause a program to exit |
|||
(unless disabled by the Trap intrinsic). |
|||
If a 'jump anywhere' must be done, inline assembly code is available. |
|||
=={{header|Yabasic}}== |
=={{header|Yabasic}}== |