Single-statement conditionals may omit the curly braces.
Note that each "case" can only test against a single value; that value can be a variable itself, but not a test expression.
If switch has no parameter, then each case is evaluated as a boolean expression, like a string of if-then statements.
try / finally
Block1 is executed as normal, and then block2 is executed regardless of whether block1 finished normally, generated an error, or encountered a 'return', 'break', or 'continue' statement.
Single-statement static declarations may omit the curly braces.
Keep in mind that when using imports, a static call will only apply to the script that imports it.
- If foo.ash has a static variable, but bar.ash imports foo.ash, KoLmafia will keep separate values for both foo.ash and bar.ash.
- If bar.ash is changed, its static variable is reset, but not foo.ash's.
- If foo.ash is changed, both scripts' variables are reset.
This is similar to the do...while loop, but only ends the loop when the
boolean expression evaluates to
Above is the general case. You don't need to specify whether it's going up or down - although doing so by using upto or downto does allow a runtime check to make sure you didn't screw up.
If you don't specify "c", it defaults to incrementing/decrementing by 1. The first iteration is at a and the last is at b (that is to say, it goes from a to b, inclusive).
Assigns each key in the supplied map or slice to "
key" and iterates through the map. Due to how maps are handled,
foreach is guaranteed to iterate through the map in sorted order.
For example:So the output is
15 test true
For a multidimensional map, instead of nesting
foreach statements two iterators can be used inline.
This is identical to:
You can also directly specify the value stored in the map by specifying one more variable than the number of keys in the map:
See the page for Data Structures for more information on aggregates.
Continuation & Exiting
Like many languages with looping structures, ASH supports the break and continue statements. All looping structures (for, while, repeat until, and foreach) support these statements.
Breaks out of the smallest enclosing loop. In a switch statement, breaks out of the switch statement. Execution resumes at the first statement after the end of the loop/switch statement.
Continues on to the next iteration of the loop (skipping any statements in this iteration that occur after the continue statement). In a switch statement, continue is allowed iff the switch is inside a loop, and acts as any other continue.
Exits the function and returns the value following the return statement, if specified. Note that the value's datatype must match that of the function itself (void functions can only use return by itself).
Exits the script. Using return when in main() achieves the same effect. Note that while this will end the current script, it will not stop automation.