Named Blocks

From Sputnik Wiki
Revision as of 12:37, 14 June 2015 by UberFoX (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to: navigation, search

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
Personal tools
Namespaces
Variants
Actions
Navigation
Toolbox