How is a language construct with the following properties called?
- It has a beginning and an end, just like a function
- It has a header containing it’s name, also like a function but without arguments
-
There can be any number of statements between its beginning and end, like a function
-
You can use a function to jump to its beginning from anywhere (even itself) and it will execute the statements contained in it until it reaches its end
-
You can use a function to immediately stop the execution of its contents and jump back where it was called from
-
The code it contains is in the same scope as everything else, so you can access all variables outside and create new ones which aren’t deleted upon leaving the construct.
All in all it is like a goto point with an end and the option to return where it was called from.
BASIC had this, it was called
gosuband its only advantage over a proper function was your last point, where all of the variables were in the same scope. Beyond that it sucked.In an object-oriented language, you could achieve generally the same effect by encapsulating the variables you want into an object and having different methods call each other. Multiple entry points are not a feature of most languages, but you can get around that by splitting your methods into smaller pieces.