Named Blocks
From Sputnik Wiki
(Difference between revisions)
(Created page with "= Name { } = === Description === A named block is similar to your normal { } block but since it has a name you can specifically *break* from that thing no matter where you a...") |
m (2 revisions) |
||
(One intermediate revision by one user not shown) | |||
Line 26: | Line 26: | ||
Name { } statements may be nested. | Name { } statements may be nested. | ||
+ | |||
+ | This is NOT the same as *goto* this statement is actually super fast since it basically simulates a return from the code and only stops returning when it reaches the named block itself then continues from the end of it. | ||
+ | |||
+ | So it is safe to use this and it will not slow down your program (unlike goto). | ||
=== Example === | === Example === |
Latest revision as of 12:37, 14 June 2015
Contents |
Name { }
Description
A named block is similar to your normal { } block but since it has a name you can specifically *break* from that thing no matter where you are inside the block.
Name { statements ... }
Parameters
Name
The name to give this named block we will need the name later in the break statement.
Block
The block of code to execute.
Remarks
Name { } statements may be nested.
This is NOT the same as *goto* this statement is actually super fast since it basically simulates a return from the code and only stops returning when it reaches the named block itself then continues from the end of it.
So it is safe to use this and it will not slow down your program (unlike goto).
Example
Break from first one
say "Begin"; hehe { say "Toy"; test { say "Cat"; { say "Dog"; if(1 == 1) { break 'hehe'; } say "Fox"; } say "Cow"; } say "Mat"; } say "End"; // Prints // Begin // Toy // Cat // Dog // End
Break from second one
say "Begin"; hehe { say "Toy"; test { say "Cat"; { say "Dog"; if(1 == 1) { break 'test'; } say "Fox"; } say "Cow"; } say "Mat"; } say "End"; // Prints // Begin // Toy // Cat // Dog // Mat // End