Control Structures: Difference between revisions
Jump to navigation
Jump to search
imported>Dj d No edit summary |
imported>Dj d |
||
Line 22: | Line 22: | ||
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). | 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). | ||
If x was previously defined, whatever value it had is restored when the for loop completes. | |||
== foreach == | == foreach == |
Revision as of 05:50, 27 September 2009
if/else
if (boolean)
{}
else if (boolean)
{}
else
{}
while
while (boolean)
{}
for
for x from a to b by c
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).
If x was previously defined, whatever value it had is restored when the for loop completes.
foreach
foreach x in map
{}
See http://kolmafia.sourceforge.net/advanced.html#maps for details.