Flow Control Effects
Commands for controlling the flow and operation of the program.

Run

1
run %Executable%
2
run %Executable% (in [the] background|async)
3
run %Executable% with %Objects%
4
run %Executable% with %Objects% (in [the] background|async)
5
run my_func()
6
run function "my_func()" in the background
7
run function "my_func(a, b)" with (1, 2)
8
run function "my_func(a, b)" with (2, 5) in the background
Copied!
Runs the given executable object. This includes directly-running functions and lambdas or dynamic functions. Some executables require parameters, given using the with... extension.
Some executables cannot be run in the background.

Break

1
(break|exit) [[the] current] section
Copied!
Jumps to the end of the current block-section, skipping any code side-effects.
1
while true:
2
print "yes"
3
break section // leaves the loop
4
print "never reached"
5
print "goes to here" // jumps to here
Copied!
Note that this break is always to the end of the current code block.
1
if 1 is 1:
2
print "yes"
3
if 2 is 2:
4
break section // leaves the current block
5
print "never reached"
6
print "yes" // jumps to here
Copied!
Unlike inline conditionals, this respects the if/else tree structure.
1
if 1 is 1:
2
print "yes"
3
break section // leaves the current block
4
print "never reached"
5
else:
6
print "never reached"
7
print "done" // jumps to here
Copied!
This has the danger of making some code unreachable, so should be used with caution to prevent unexpected behaviour.

Break If

1
(break|exit) [[the] current] section if %Boolean%
Copied!
A variant of the break effect with a conditional value.
1
while true:
2
print "yes"
3
break section if {var} is true // leaves the loop if {var} is true
4
print "might still run"
5
print "goes to here" // jumps to here
Copied!
Since the break effect may not be useful inside if/else condition sub-sections (since it would break that condition rather than the closing block), this provides a way to use it conditionally, if a particular block needs to be broken.

Break Loop

1
(break|exit) [[the] current] loop
Copied!
A variant of the break effect that targets a loop.
1
while true:
2
print "yes"
3
if {var} is true:
4
break loop // leaves the loop
5
print "might still run"
6
print "goes to here" // jumps to here
Copied!
Provides an alternative to the break effect that targets the first available loop in the flow tree and exits it.
Unlike the break effect, exit loop will work in sub-sections.
1
loop {word} in {list}:
2
print "hello " + {item}
3
if 1 is 1:
4
if 2 is 2:
5
exit loop // breaks the loop
6
print "never reached"
7
print "exited early" // jumps down to here
Copied!

Continue

1
continue [[the] current] loop
Copied!
Jumps to the start of the current loop, skipping any code side-effects.
1
while true: // jumps back up to here
2
print "yes"
3
continue loop // back to the top
4
print "never reached"
Copied!
This will begin the next iteration of the loop.
1
loop {word} in {list}: // jumps back up to here
2
print "hello " + {item}
3
continue loop // back to the top
4
print "never reached"
5
print "finished"
Copied!
Unlike the break effect, continue will work in sub-sections.
1
loop {word} in {list}: // jumps back up to here
2
print "hello " + {item}
3
if 1 is 1:
4
if 2 is 2:
5
continue loop // back to the top
6
print "never reached"
7
print "finished"
Copied!

Exit Program

1
exit [the] program
Copied!
Terminates the JVM process with exit code 0.
1
if {should_end} is true:
2
exit program
Copied!

Return Value

1
return %Object%
2
return true
3
return {var}
4
return 1 + 1
Copied!
Returns a value from the current function or supplier.
1
function my_func:
2
trigger:
3
return "hello"
Copied!
Nothing below the return instruction will be run.
1
function my_func:
2
trigger:
3
print "is run"
4
return "hello"
5
print "never run"
Copied!
The return can be used in conditional sections.
1
function my_func:
2
trigger:
3
if 1 is 1:
4
return "hello"
Copied!
Multiple returns can be used based on different conditions.
1
function my_func:
2
trigger:
3
if 1 is 2:
4
return "no"
5
else:
6
return "yes"
Copied!
The return value is received by the executor.
1
function my_func:
2
trigger:
3
print is_true(true) // "yes"
4
print is_true(55) // "no"
5
​
6
function is_true(value):
7
trigger:
8
if {value} is true:
9
return "yes"
10
return "no"
Copied!

Stop

1
(stop|return)
2
return
3
stop
Copied!
This is the equivalent to the return effect but with no value. The code tree is simply ended.
1
function my_func:
2
trigger:
3
if 1 is 1:
4
return
5
print "yes"
Copied!
If the caller was expecting a value, it will be given the empty null value.
1
function my_func:
2
trigger:
3
print is_true(true) // "yes"
4
print is_true(55) // null
5
​
6
function is_true(value):
7
trigger:
8
if {value} is true:
9
return "yes"
10
return // gives back 'null'
Copied!

Assert

1
assert %Boolean%
2
assert 1 is 1
3
assert 1 is not 2
4
assert "hello" is a string
Copied!
The assertion effect is designed for testing and verifying assumptions about code. If the value given is false, an error will be thrown that stops the current execution.
If the value is true the assertion will pass silently and no error will be thrown.
1
function broadcast (value):
2
trigger:
3
assert {value} is a string
4
print {value}
Copied!
This is designed to be used with the verifier entry for functions.
This is used during the test phase when building Skript to check that syntaxes work as expected.