<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.kolmafia.us/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=210.119.98.20</id>
	<title>Kolmafia - User contributions [en]</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.kolmafia.us/api.php?action=feedcontributions&amp;feedformat=atom&amp;user=210.119.98.20"/>
	<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Special:Contributions/210.119.98.20"/>
	<updated>2026-04-25T02:01:25Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://wiki.kolmafia.us/index.php?title=Control_Structures&amp;diff=3159</id>
		<title>Control Structures</title>
		<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Control_Structures&amp;diff=3159"/>
		<updated>2010-06-16T08:36:26Z</updated>

		<summary type="html">&lt;p&gt;210.119.98.20: /* foreach */ whoops, mistake&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{TOCright}}&lt;br /&gt;
==Conditional==&lt;br /&gt;
===if===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
if ( boolean )&lt;br /&gt;
{&lt;br /&gt;
   // any statements here&lt;br /&gt;
   // are only going to be executed&lt;br /&gt;
   // if the boolean returns true&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
description=Single-statement conditionals may omit the curly braces.|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
if ( boolean )&lt;br /&gt;
   // curly braces aren&#039;t required if only one statement follows the conditional&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
===else===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
if ( boolean )&lt;br /&gt;
{&lt;br /&gt;
   // statements if true&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
   // the statements here&lt;br /&gt;
   // are only going to be executed&lt;br /&gt;
   // if the boolean returns false&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===else if===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
if ( boolean 1 )&lt;br /&gt;
{&lt;br /&gt;
   // statements if true&lt;br /&gt;
}&lt;br /&gt;
else if ( boolean 2 )&lt;br /&gt;
{&lt;br /&gt;
   // the statements here&lt;br /&gt;
   // are only going to be executed&lt;br /&gt;
   // if boolean 1 returns false&lt;br /&gt;
   // &amp;amp; boolean 2 returns true&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===switch===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
switch ( variable )&lt;br /&gt;
{&lt;br /&gt;
   case value:&lt;br /&gt;
      // statements if variable == value&lt;br /&gt;
      // more such statements&lt;br /&gt;
      break;&lt;br /&gt;
   //repeat above for as many values as desired&lt;br /&gt;
   default:&lt;br /&gt;
      // statements executed if&lt;br /&gt;
      // none of the cases were true&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Note that each &amp;quot;case&amp;quot; can only test against a single value; that value can be a variable itself, but not a test expression.&lt;br /&gt;
&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
description=If switch has no parameter, then each case is evaluated as a boolean expression, like a string of if-then statements.|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
switch&lt;br /&gt;
{&lt;br /&gt;
   case boolean expression:&lt;br /&gt;
      // if the expression is true, this statement is executed&lt;br /&gt;
      // more such statements&lt;br /&gt;
      break;&lt;br /&gt;
   //repeat above for as many conditionals as desired&lt;br /&gt;
   default:&lt;br /&gt;
      // statements executed if&lt;br /&gt;
      // none of the cases were true&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==Loops==&lt;br /&gt;
===while===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
while ( boolean )&lt;br /&gt;
{&lt;br /&gt;
   // as with an if statement&lt;br /&gt;
   // this area is only entered&lt;br /&gt;
   // if the boolean tests true&lt;br /&gt;
   // once all this is done&lt;br /&gt;
   // it goes back to the begining&lt;br /&gt;
   // and will keep executing&lt;br /&gt;
   // as long as the boolean remains true&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===repeat until===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
repeat&lt;br /&gt;
{&lt;br /&gt;
   // this is the same&lt;br /&gt;
   // as the while loop above&lt;br /&gt;
   // with one exception:&lt;br /&gt;
   // all of this code will&lt;br /&gt;
   // execute at least once&lt;br /&gt;
   // as the test doesn&#039;t occur&lt;br /&gt;
   // until the very end&lt;br /&gt;
} until ( boolean )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===for===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
for x from a to b by c {&lt;br /&gt;
   //do stuff&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
Above is the general case. You don&#039;t need to specify whether it&#039;s going up or down - although doing so by using upto or downto does allow a runtime check to make sure you didn&#039;t screw up.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t specify &amp;quot;c&amp;quot;, 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).&lt;br /&gt;
&lt;br /&gt;
===foreach===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
foreach key in aggregate {&lt;br /&gt;
   //do stuff&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
Assigns each key in the supplied map or slice to &amp;quot;key&amp;quot; and iterates through the map.&lt;br /&gt;
&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
description=For example:|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
boolean [int][string] map;&lt;br /&gt;
map[15][&amp;quot;test&amp;quot;] = true;&lt;br /&gt;
foreach int_index in map {&lt;br /&gt;
   print(int_index); //this will print &#039;15&#039; once, since there is only one valid value for this index&lt;br /&gt;
   foreach string_index in map[int_index] //this iterates over the &amp;quot;slice&amp;quot; of the map where 1 is fixed as the index&lt;br /&gt;
   { &lt;br /&gt;
      print(string_index); //This will print &amp;quot;test&amp;quot; once, since there is only one valid value for this index&lt;br /&gt;
      print(map[int_index][string_index]); //this will print &amp;quot;true&amp;quot;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;|&lt;br /&gt;
moreinfo=&lt;br /&gt;
So the output is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
15&lt;br /&gt;
test&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
description=Note that instead of nesting foreach statements, for a multidimensional map, two iterators can be used inline.|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
foreach x,y in map {&lt;br /&gt;
   //do stuff&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
description=This is identical to:|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
foreach x in map {&lt;br /&gt;
   foreach y in map[x] {&lt;br /&gt;
      //do stuff&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CodeSample|&lt;br /&gt;
description=You can also directly specify the value stored in the map by specifying one more variable than the number of keys in the map:|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
//string [string, int, item] my_map;&lt;br /&gt;
foreach s, i, m, value in my_map {&lt;br /&gt;
    print( s + &amp;quot;, &amp;quot; + i + &amp;quot;, &amp;quot; + m + &amp;quot; =&amp;gt; &amp;quot; + value );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
}}&lt;br /&gt;
&lt;br /&gt;
See the page for [[Data Structures]] for more information on aggregates.&lt;br /&gt;
&lt;br /&gt;
==Continuation &amp;amp; Exiting==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===break===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===continue===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===return===&lt;br /&gt;
Exits the function and returns the value following the return statement, if specified. Note that the value&#039;s datatype must match that of the function itself (void functions can only use return by itself).&lt;br /&gt;
&lt;br /&gt;
[[Category:ASH Scripting]]&lt;/div&gt;</summary>
		<author><name>210.119.98.20</name></author>
	</entry>
	<entry>
		<id>https://wiki.kolmafia.us/index.php?title=Control_Structures&amp;diff=3158</id>
		<title>Control Structures</title>
		<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Control_Structures&amp;diff=3158"/>
		<updated>2010-06-16T08:35:30Z</updated>

		<summary type="html">&lt;p&gt;210.119.98.20: Added &amp;quot;one-more-var-than-the-number-of-keys&amp;quot; information&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{TOCright}}&lt;br /&gt;
==Conditional==&lt;br /&gt;
===if===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
if ( boolean )&lt;br /&gt;
{&lt;br /&gt;
   // any statements here&lt;br /&gt;
   // are only going to be executed&lt;br /&gt;
   // if the boolean returns true&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
description=Single-statement conditionals may omit the curly braces.|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
if ( boolean )&lt;br /&gt;
   // curly braces aren&#039;t required if only one statement follows the conditional&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
===else===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
if ( boolean )&lt;br /&gt;
{&lt;br /&gt;
   // statements if true&lt;br /&gt;
}&lt;br /&gt;
else&lt;br /&gt;
{&lt;br /&gt;
   // the statements here&lt;br /&gt;
   // are only going to be executed&lt;br /&gt;
   // if the boolean returns false&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===else if===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
if ( boolean 1 )&lt;br /&gt;
{&lt;br /&gt;
   // statements if true&lt;br /&gt;
}&lt;br /&gt;
else if ( boolean 2 )&lt;br /&gt;
{&lt;br /&gt;
   // the statements here&lt;br /&gt;
   // are only going to be executed&lt;br /&gt;
   // if boolean 1 returns false&lt;br /&gt;
   // &amp;amp; boolean 2 returns true&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===switch===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
switch ( variable )&lt;br /&gt;
{&lt;br /&gt;
   case value:&lt;br /&gt;
      // statements if variable == value&lt;br /&gt;
      // more such statements&lt;br /&gt;
      break;&lt;br /&gt;
   //repeat above for as many values as desired&lt;br /&gt;
   default:&lt;br /&gt;
      // statements executed if&lt;br /&gt;
      // none of the cases were true&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
Note that each &amp;quot;case&amp;quot; can only test against a single value; that value can be a variable itself, but not a test expression.&lt;br /&gt;
&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
description=If switch has no parameter, then each case is evaluated as a boolean expression, like a string of if-then statements.|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
switch&lt;br /&gt;
{&lt;br /&gt;
   case boolean expression:&lt;br /&gt;
      // if the expression is true, this statement is executed&lt;br /&gt;
      // more such statements&lt;br /&gt;
      break;&lt;br /&gt;
   //repeat above for as many conditionals as desired&lt;br /&gt;
   default:&lt;br /&gt;
      // statements executed if&lt;br /&gt;
      // none of the cases were true&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
==Loops==&lt;br /&gt;
===while===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
while ( boolean )&lt;br /&gt;
{&lt;br /&gt;
   // as with an if statement&lt;br /&gt;
   // this area is only entered&lt;br /&gt;
   // if the boolean tests true&lt;br /&gt;
   // once all this is done&lt;br /&gt;
   // it goes back to the begining&lt;br /&gt;
   // and will keep executing&lt;br /&gt;
   // as long as the boolean remains true&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===repeat until===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
repeat&lt;br /&gt;
{&lt;br /&gt;
   // this is the same&lt;br /&gt;
   // as the while loop above&lt;br /&gt;
   // with one exception:&lt;br /&gt;
   // all of this code will&lt;br /&gt;
   // execute at least once&lt;br /&gt;
   // as the test doesn&#039;t occur&lt;br /&gt;
   // until the very end&lt;br /&gt;
} until ( boolean )&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
===for===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
for x from a to b by c {&lt;br /&gt;
   //do stuff&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
Above is the general case. You don&#039;t need to specify whether it&#039;s going up or down - although doing so by using upto or downto does allow a runtime check to make sure you didn&#039;t screw up.&lt;br /&gt;
&lt;br /&gt;
If you don&#039;t specify &amp;quot;c&amp;quot;, 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).&lt;br /&gt;
&lt;br /&gt;
===foreach===&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
foreach key in aggregate {&lt;br /&gt;
   //do stuff&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
Assigns each key in the supplied map or slice to &amp;quot;key&amp;quot; and iterates through the map.&lt;br /&gt;
&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
description=For example:|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
boolean [int][string] map;&lt;br /&gt;
map[15][&amp;quot;test&amp;quot;] = true;&lt;br /&gt;
foreach int_index in map {&lt;br /&gt;
   print(int_index); //this will print &#039;15&#039; once, since there is only one valid value for this index&lt;br /&gt;
   foreach string_index in map[int_index] //this iterates over the &amp;quot;slice&amp;quot; of the map where 1 is fixed as the index&lt;br /&gt;
   { &lt;br /&gt;
      print(string_index); //This will print &amp;quot;test&amp;quot; once, since there is only one valid value for this index&lt;br /&gt;
      print(map[int_index][string_index]); //this will print &amp;quot;true&amp;quot;&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;|&lt;br /&gt;
moreinfo=&lt;br /&gt;
So the output is&lt;br /&gt;
&amp;lt;pre&amp;gt;&lt;br /&gt;
15&lt;br /&gt;
test&lt;br /&gt;
true&lt;br /&gt;
&amp;lt;/pre&amp;gt;}}&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
description=Note that instead of nesting foreach statements, for a multidimensional map, two iterators can be used inline.|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
foreach x,y in map {&lt;br /&gt;
   //do stuff&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
description=This is identical to:|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
foreach x in map {&lt;br /&gt;
   foreach y in map[x] {&lt;br /&gt;
      //do stuff&lt;br /&gt;
   }&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
{{CodeSample|&lt;br /&gt;
description=You can also directly specify the value stored in the map by specifying one more variable than the number of keys in the map:|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
//string [string, int, item] my_map;&lt;br /&gt;
foreach s, i, m, value in my_map {&lt;br /&gt;
    print( s + &amp;quot;, &amp;quot; + i + &amp;quot;, &amp;quot; + m + &amp;quot; =&amp;gt; &amp;quot; + value );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;&lt;br /&gt;
&lt;br /&gt;
See the page for [[Data Structures]] for more information on aggregates.&lt;br /&gt;
&lt;br /&gt;
==Continuation &amp;amp; Exiting==&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===break===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===continue===&lt;br /&gt;
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.&lt;br /&gt;
&lt;br /&gt;
===return===&lt;br /&gt;
Exits the function and returns the value following the return statement, if specified. Note that the value&#039;s datatype must match that of the function itself (void functions can only use return by itself).&lt;br /&gt;
&lt;br /&gt;
[[Category:ASH Scripting]]&lt;/div&gt;</summary>
		<author><name>210.119.98.20</name></author>
	</entry>
	<entry>
		<id>https://wiki.kolmafia.us/index.php?title=Data_Structures&amp;diff=3188</id>
		<title>Data Structures</title>
		<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Data_Structures&amp;diff=3188"/>
		<updated>2010-06-16T01:40:25Z</updated>

		<summary type="html">&lt;p&gt;210.119.98.20: Modified headers and properly located the Records section- PhilmASTErpLus&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{TOCright}}&lt;br /&gt;
== Maps ==&lt;br /&gt;
Most of this information was copied directly from ASH Maps Tutorial, by Veracity &lt;br /&gt;
(http://kolmafia.sourceforge.net/advanced.html#maps)&lt;br /&gt;
&lt;br /&gt;
A map is indexed by one data type (the key) and associates that key with another (or the same) data type (the value). The key can be any ASH simple data type: boolean, int, float, string, item, location, class, stat, skill, effect, familiar, slot, or monster. The value can be any ASH data type at all: a simple type, a record, or can be an aggregate - another map. This effectively allows multi-dimensional maps and. In fact, that&#039;s how the syntax we provide for multi-dimensional aggregates actually operates: maps of maps of maps ...&lt;br /&gt;
&lt;br /&gt;
You can declare a map any time you can declare a variable: as a top level (global) variable, as a function parameter, or as a local variable in any scope.&lt;br /&gt;
&lt;br /&gt;
You can fetch data from a map any time you can provide a data value: in an expression, as a function parameter, on the right side of an assignment statement, from a &amp;quot;return&amp;quot; statement, as so on. You can pass around entire maps, individual elements, or intermediate maps: &amp;quot;slices&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Assignments ===&lt;br /&gt;
&lt;br /&gt;
If you use a map on the left side of an assignment, you set the whole map at once to the new value. If you specify a map and a complete set of indices (of the correct types) on the left side of an assignment statement, you set a single element. If you specify a map and a prefix of indices (of the correct type), you directly set one of the intermediate maps, a &amp;quot;slice&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
=== Declarations ===&lt;br /&gt;
&lt;br /&gt;
The syntax for declaring the data type of a map:&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;data type&amp;gt; [ &amp;lt;key type&amp;gt;, ... ]  &lt;br /&gt;
&lt;br /&gt;
=== References ===&lt;br /&gt;
&lt;br /&gt;
The syntax for referencing an element (or slice) of a map:&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;variablename&amp;gt;[ &amp;lt;key expression&amp;gt;, ... ]  &lt;br /&gt;
&lt;br /&gt;
All the key expressions will be evaluated at run time. If you specify all the keys the map expects, you fetch data of the type specified by the map. If you specify fewer keys than the map expects, you get an intermediate map, a &amp;quot;slice&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
As an example:&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
   boolean [string, string] props; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
&lt;br /&gt;
might be used to hold &amp;quot;properties&amp;quot; associated with names.&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
props[ &amp;quot;dog&amp;quot;, &amp;quot;mammal&amp;quot; ] = true; &lt;br /&gt;
props[ &amp;quot;dog&amp;quot;, &amp;quot;pet&amp;quot; ] = true; &lt;br /&gt;
props[ &amp;quot;dog&amp;quot;, &amp;quot;fun&amp;quot; ] = false;&lt;br /&gt;
props[ &amp;quot;turtle&amp;quot;, &amp;quot;mammal&amp;quot; ] = false;&lt;br /&gt;
props[ &amp;quot;turtle&amp;quot;, &amp;quot;pet&amp;quot; ] = true;&lt;br /&gt;
props[ &amp;quot;turtle&amp;quot;, &amp;quot;fun&amp;quot; ] = false;&lt;br /&gt;
props[ &amp;quot;aardvark&amp;quot;, &amp;quot;mammal&amp;quot; ] = true;&lt;br /&gt;
props[ &amp;quot;aardvark&amp;quot;, &amp;quot;pet&amp;quot; ] = false;&lt;br /&gt;
props[ &amp;quot;aardvark&amp;quot;, &amp;quot;fun&amp;quot; ] = true; &lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
 &lt;br /&gt;
&lt;br /&gt;
references:&lt;br /&gt;
&lt;br /&gt;
    props[ &amp;quot;dog&amp;quot;, &amp;quot;mammal&amp;quot;] =&amp;gt; true &lt;br /&gt;
    boolean [string] animal = props[ &amp;quot;turtle&amp;quot; ]; &lt;br /&gt;
    animal[ &amp;quot;fun&amp;quot; ] =&amp;gt; false  &lt;br /&gt;
&lt;br /&gt;
=== Contains ===&lt;br /&gt;
&lt;br /&gt;
You can test the presence of a key in a map using the &amp;quot;contains&amp;quot; operator:&lt;br /&gt;
&lt;br /&gt;
    &amp;lt;aggregate reference expression&amp;gt; contains &amp;lt;key expression&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
Where &amp;lt;aggregate reference expression&amp;gt; must evaluate at run time to a map or slice, and must evaluate at run time to a key of the appropriate type. (Note that that is enforced at parse time; ASH can tell the datatype any expression will produce).&lt;br /&gt;
&lt;br /&gt;
    props contains &amp;quot;dog&amp;quot; =&amp;gt; true &lt;br /&gt;
    props contains &amp;quot;elephant&amp;quot; =&amp;gt; false &lt;br /&gt;
    props[ &amp;quot;aardvark&amp;quot; ] contains &amp;quot;fun&amp;quot; =&amp;gt; true &lt;br /&gt;
    animal contains &amp;quot;pet&amp;quot; =&amp;gt; true &lt;br /&gt;
    animal contains &amp;quot;favorite food&amp;quot; =&amp;gt; false  &lt;br /&gt;
&lt;br /&gt;
=== Remove ===&lt;br /&gt;
&lt;br /&gt;
You can remove a key-value association from a map using the &amp;quot;remove&amp;quot; unary operator:&lt;br /&gt;
&lt;br /&gt;
    remove &amp;lt;aggregate reference&amp;gt;  &lt;br /&gt;
&lt;br /&gt;
For clarification, an aggregate reference is &amp;quot;&amp;lt;map name&amp;gt;[ &amp;lt;index 1&amp;gt; ... &amp;lt;index n&amp;gt; ]&amp;quot; where &amp;lt;map name&amp;gt;[ &amp;lt;index 1&amp;gt; ... &amp;lt;index n-1&amp;gt; ] specifies the &amp;quot;slice&amp;quot; and &amp;lt;index n&amp;gt; specifies the &amp;quot;key&amp;quot;. Which is just what you expect, if you fully specify the indices; for a single dimensional map, &amp;quot;map[10]&amp;quot; -&amp;gt; &amp;quot;map&amp;quot; is the slice and 10 is the key. The &amp;quot;remove&amp;quot; operator removes the &amp;quot;key&amp;quot; from the &amp;quot;slice&amp;quot;. For example:&lt;br /&gt;
&lt;br /&gt;
  string [int] map1;&lt;br /&gt;
  map1[5] = &amp;quot;foo&amp;quot;;&lt;br /&gt;
  print( count( map1 ) + &amp;quot; &amp;quot; + map1 contains 5 + &amp;quot; &amp;quot; + map1[5] );&lt;br /&gt;
  print( &amp;quot;remove: &amp;quot; + remove map1[5] );&lt;br /&gt;
  print( count( map1 ) + &amp;quot; &amp;quot; + map1 contains 5 + &amp;quot; &amp;quot;  + map1[5] );&lt;br /&gt;
  print( &amp;quot;remove: &amp;quot; + remove map1[5] );&lt;br /&gt;
  int [string, string] map2;&lt;br /&gt;
  map2[&amp;quot;me&amp;quot;,&amp;quot;you&amp;quot;] = 17;&lt;br /&gt;
  print( count( map2[&amp;quot;me&amp;quot;] ) + &amp;quot; &amp;quot; + map2[&amp;quot;me&amp;quot;] contains &amp;quot;you&amp;quot; + &amp;quot; &amp;quot; + map2[&amp;quot;me&amp;quot;,&amp;quot;you&amp;quot;] );&lt;br /&gt;
  print( &amp;quot;remove: &amp;quot; + remove map2[&amp;quot;me&amp;quot;, &amp;quot;you&amp;quot;] );&lt;br /&gt;
  print( count( map2[&amp;quot;me&amp;quot;] ) + &amp;quot; &amp;quot; + map2[&amp;quot;me&amp;quot;] contains &amp;quot;you&amp;quot; + &amp;quot; &amp;quot; + map2[&amp;quot;me&amp;quot;,&amp;quot;you&amp;quot;] );&lt;br /&gt;
  print( &amp;quot;remove: &amp;quot; + remove map2[&amp;quot;me&amp;quot;, &amp;quot;you&amp;quot;] );&lt;br /&gt;
  print( count( map2 ) + &amp;quot; &amp;quot; + map2[&amp;quot;me&amp;quot;] );&lt;br /&gt;
  print( &amp;quot;remove: &amp;quot; + remove map2[&amp;quot;me&amp;quot;] );&lt;br /&gt;
  print( count( map2 ) + &amp;quot; &amp;quot; + map2[&amp;quot;me&amp;quot;] );&lt;br /&gt;
&lt;br /&gt;
yields:&lt;br /&gt;
&lt;br /&gt;
  1 true foo&lt;br /&gt;
  remove: foo&lt;br /&gt;
  0 false&lt;br /&gt;
  remove:&lt;br /&gt;
  1 true 17&lt;br /&gt;
  remove: 17&lt;br /&gt;
  0 false 0&lt;br /&gt;
  remove: 0&lt;br /&gt;
  1 aggregate int [string]&lt;br /&gt;
  remove: aggregate int [string]&lt;br /&gt;
  0 aggregate int [string]&lt;br /&gt;
&lt;br /&gt;
=== Deletion ===&lt;br /&gt;
&lt;br /&gt;
clear (theMap) will remove all entries&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
=== Sort ===&lt;br /&gt;
&lt;br /&gt;
From http://kolmafia.us/showthread.php?t=1738&lt;br /&gt;
&lt;br /&gt;
The syntax is:&lt;br /&gt;
sort aggregate by keyExpr;&lt;br /&gt;
aggregate is a reference to the object to be sorted - arrays are probably the most useful things to sort, but any mapping type can be used (even multidimensional maps, but note that you can only sort along a single dimension at a time). The reference must not be enclosed in parentheses, as that would look like a call to a function named sort() - which is still perfectly valid, &amp;quot;sort&amp;quot; has not become a [[Reserved Words|reserved word]].&lt;br /&gt;
&lt;br /&gt;
keyExpr is an arbitrary expression that defines how the items should be ordered. It is evaluated once for every entry in the aggregate, in a scope with two additional variables implicitly defined: &#039;index&#039; and &#039;value&#039;, holding the details of that entry. The value of the keyExpr is used as the sort key; typically it would be an int or string, but can be any ASH type that can be compared via &amp;quot;&amp;lt;&amp;quot; and the other relational operators.&lt;br /&gt;
&lt;br /&gt;
The most basic form of sorting would therefore be &amp;quot;sort ... by value&amp;quot;, but many useful things can be done with the use of a more complex keyExpr - the only real restriction is that the expression should not modify the object you&#039;re sorting. For example, if you had an array of items, you could sort it &amp;quot;by autosell_price(value)&amp;quot;. An array of weapon items could be sorted &amp;quot;by -get_power(value)&amp;quot; to put it in decreasing order of power. If the elements of your aggregate are records, you&#039;d need to use something like &amp;quot;by value.fieldName&amp;quot;, since the records themselves can&#039;t be meaningfully compared.&lt;br /&gt;
&lt;br /&gt;
After the sort statement, the aggregate will have exactly the same sets of keys and values as before (even if the keys weren&#039;t consecutive), and the iteration order of the keys will be the same, but the values will likely be associated with different keys. The sort is stable - in other words, elements with sort keys that compare as equal will remain in the same order. This means that you can sort on multiple criteria by simply performing separate sorts for each of the criteria, in increasing order of significance.&lt;br /&gt;
&lt;br /&gt;
A few more examples of things you can do:&lt;br /&gt;
* &amp;quot;by -value&amp;quot; sorts integers in decreasing order (there&#039;s no similar trick for string values).&lt;br /&gt;
* &amp;quot;by -index&amp;quot; reverses the existing order of an array (or map with integer keys).&lt;br /&gt;
* &amp;quot;by random(1000000)&amp;quot; shuffles into a random order.&lt;br /&gt;
* &amp;quot;by otherArray[index]&amp;quot; uses values from a parallel array as the sort keys (you&#039;d then need to do &amp;quot;sort otherArray by value;&amp;quot; if you wanted the two arrays to remain in sync).&lt;br /&gt;
&lt;br /&gt;
== Records ==&lt;br /&gt;
&lt;br /&gt;
(copy-pasted from Veracity&#039;s post introducing the record [http://kolmafia.us/showthread.php?t=280])&lt;br /&gt;
&lt;br /&gt;
Starting with SVN revision 1311 of KoLmafia, ASH now supports a new kind of structured data: the record. Here is a little example of how you declare a record and variables of the new type you&#039;ve created by doing so.&lt;br /&gt;
&lt;br /&gt;
  record my_type {&lt;br /&gt;
  	int ifield;&lt;br /&gt;
  	string sfield;&lt;br /&gt;
  	record {&lt;br /&gt;
  		int first;&lt;br /&gt;
  		int second;&lt;br /&gt;
  	} rfield;&lt;br /&gt;
  	int [int, int] mfield;&lt;br /&gt;
  };&lt;br /&gt;
  &lt;br /&gt;
  my_type rvar;&lt;br /&gt;
  my_type [int] mrvar;&lt;br /&gt;
&lt;br /&gt;
What I&#039;ve done with the above is declare a new data type which I&#039;ve named &amp;quot;my_type&amp;quot;. Having declared the new type, I can use it (almost) anywhere that I can use a built-in type name. I declared a variable, &amp;quot;rvar&amp;quot;, of that type, and I defined a map, &amp;quot;mrvar&amp;quot;, which maps keys of type integer to values of type my_type.&lt;br /&gt;
&lt;br /&gt;
The new type, &amp;quot;my_type&amp;quot; is a &amp;quot;composite&amp;quot; type. It contains four fields. &amp;quot;ifield&amp;quot; is an integer. &amp;quot;sfield&amp;quot; is a string. &amp;quot;rfield&amp;quot; is another composite field: an anonymous record containing two integers named &amp;quot;first&amp;quot; and &amp;quot;second&amp;quot;. Finally, &amp;quot;mfield&amp;quot; is a map from [int, int] to int.&lt;br /&gt;
&lt;br /&gt;
As you can see, a record can combine data of all the types ASH supports: primitive, aggregate, and composite.&lt;br /&gt;
&lt;br /&gt;
Having defined the new data type and several variables using it, here are some examples of how to access the fields.&lt;br /&gt;
&lt;br /&gt;
  rvar.ifield = 10;&lt;br /&gt;
  rvar.sfield = &amp;quot;secret&amp;quot;;&lt;br /&gt;
  rvar.rfield.first = 1000;&lt;br /&gt;
  rvar.sfield.second = 2000;&lt;br /&gt;
  rvar.mfield[ 2, 3 ] = 12;&lt;br /&gt;
  &lt;br /&gt;
  mrvar[ 1 ] = rvar;&lt;br /&gt;
  &lt;br /&gt;
  foreach key in mrvar&lt;br /&gt;
  	foreach key1, key2 in mrvar[key].mfield&lt;br /&gt;
  		print( &amp;quot;val = &amp;quot; + mrvar[key].mfield[key1,key2] );&lt;br /&gt;
&lt;br /&gt;
As you can see, if you have a variable that is a record, you access the fields of the record by following the variable name with &amp;quot;.&amp;amp;lt;field name&amp;amp;gt;&amp;quot;. The resulting value will be of whatever type you declared in the definition of the record. If the value is a map, you can give a list of keys within [], just like any other map. If the value is another record, you can access the fields of the nested record by using another &amp;quot;.&amp;amp;lt;field name&amp;amp;gt;&amp;quot;.&lt;br /&gt;
&lt;br /&gt;
If you are familiar with Pascal &amp;quot;records&amp;quot; or C/C++ &amp;quot;structs&amp;quot;, this should all be comfortably familiar.&lt;br /&gt;
&lt;br /&gt;
Finally, if you create a map whose values is a record, the file_to_map and map_to_file built-in ASH functions will Do The Right Thing; they will efficiently and reliably save and restore your data.&lt;br /&gt;
{{RFI|I, for one, don&#039;t have a good handle on multi-dimensional maps. Any effort to clarify how they are defined &amp;amp; accessed would be greatly appreciated.|Don&#039;t worry about formatting for now; I&#039;ll get to that once the info is there, unless you&#039;re feeling super-ambitious.}}&lt;br /&gt;
{{Format}}&lt;br /&gt;
&lt;br /&gt;
[[Category:ASH Scripting]]&lt;/div&gt;</summary>
		<author><name>210.119.98.20</name></author>
	</entry>
</feed>