<?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=68.157.42.151</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=68.157.42.151"/>
	<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Special:Contributions/68.157.42.151"/>
	<updated>2026-04-30T16:56:38Z</updated>
	<subtitle>User contributions</subtitle>
	<generator>MediaWiki 1.44.0</generator>
	<entry>
		<id>https://wiki.kolmafia.us/index.php?title=Operators&amp;diff=1873</id>
		<title>Operators</title>
		<link rel="alternate" type="text/html" href="https://wiki.kolmafia.us/index.php?title=Operators&amp;diff=1873"/>
		<updated>2010-05-12T05:02:54Z</updated>

		<summary type="html">&lt;p&gt;68.157.42.151: /* Mathematical Operators */&lt;/p&gt;
&lt;hr /&gt;
&lt;div&gt;{{TOCright}}&lt;br /&gt;
==Mathematical Operators==&lt;br /&gt;
&lt;br /&gt;
The following mathematical operators are used in KoLmafia:&lt;br /&gt;
{{&lt;br /&gt;
eztable|&lt;br /&gt;
{{eztr|{{eztd| + |Addition|Performs addition and string concatenation}}}}&lt;br /&gt;
{{eztr|{{eztd| - |Subtraction|Performs subtraction}}}}&lt;br /&gt;
{{eztr|{{eztd| * |Multiplication|Performs multiplication}}}}&lt;br /&gt;
{{eztr|{{eztd| / |Division|Performs division}}}}&lt;br /&gt;
{{eztr|{{eztd| % |Modulo|Returns the remainder after division}}}}&lt;br /&gt;
{{eztr|{{eztd| ^ |Exponent|Performs exponentiation}}}}&lt;br /&gt;
}}&lt;br /&gt;
Note that, with the exception of using &amp;lt;nowiki&amp;gt;&amp;quot;+&amp;quot;&amp;lt;/nowiki&amp;gt; for string concatenation, these operators can only be used on int or float datatypes.&lt;br /&gt;
&lt;br /&gt;
==Assignment Operators==&lt;br /&gt;
The following assignment operators are used in KoLmafia (let a = left operand, b = right operand):&lt;br /&gt;
{{&lt;br /&gt;
eztable|&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;=&amp;lt;/nowiki&amp;gt; |&amp;lt;nowiki&amp;gt;a = b&amp;lt;/nowiki&amp;gt;}}}}&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;+=&amp;lt;/nowiki&amp;gt; |&amp;lt;nowiki&amp;gt;a = a + b&amp;lt;/nowiki&amp;gt;}}}}&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;-=&amp;lt;/nowiki&amp;gt; |&amp;lt;nowiki&amp;gt;a = a - b&amp;lt;/nowiki&amp;gt;}}}}&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;*=&amp;lt;/nowiki&amp;gt; |&amp;lt;nowiki&amp;gt;a = a * b&amp;lt;/nowiki&amp;gt;}}}}&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;/=&amp;lt;/nowiki&amp;gt; |&amp;lt;nowiki&amp;gt;a = a / b&amp;lt;/nowiki&amp;gt;}}}}&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;%=&amp;lt;/nowiki&amp;gt; |&amp;lt;nowiki&amp;gt;a = a % b&amp;lt;/nowiki&amp;gt;}}}}&lt;br /&gt;
}}&lt;br /&gt;
Of these, only += and = are usable for strings.  See [[Operators#Mathematical Operators|Mathematical Operators]] for information regarding the basic Mathematical Operators.&lt;br /&gt;
&lt;br /&gt;
==Relational Operators==&lt;br /&gt;
&lt;br /&gt;
To follow these examples, a basic understanding of the concepts found on [[Control Structures]] would be helpful.&lt;br /&gt;
&lt;br /&gt;
In order to create more complex if statements, we need to understand the basic relational operators:&lt;br /&gt;
{{&lt;br /&gt;
eztable|&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;==&amp;lt;/nowiki&amp;gt; |equal to}}}}&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;!=&amp;lt;/nowiki&amp;gt; |not equal to}}}}&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;&amp;lt;&amp;lt;/nowiki&amp;gt; |less than}}}}&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;&amp;gt;&amp;lt;/nowiki&amp;gt; |greater than}}}}&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;&amp;lt;=&amp;lt;/nowiki&amp;gt; |less than or equal to}}}}&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;&amp;gt;=&amp;lt;/nowiki&amp;gt; |greater than or equal to}}}}&lt;br /&gt;
}}&lt;br /&gt;
Note that you cannot mix datatypes within a comparison or KoLmafia will abort with an error, with the exception of mixing types int and float, where KoLmafia will do a transparent type conversion behind-the-scenes. If you need to compare different datatypes, use one or more of the [[Datatype Conversions|Datatype Conversion]] functions. Also, == is case-insensitive with respect to strings.&lt;br /&gt;
&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
if ( true == true )&lt;br /&gt;
{&lt;br /&gt;
   print( &amp;quot;This line DOES get printed.&amp;quot; );&lt;br /&gt;
}&lt;br /&gt;
if ( true == false )&lt;br /&gt;
{&lt;br /&gt;
   print( &amp;quot;This line does NOT get printed.&amp;quot; );&lt;br /&gt;
}&lt;br /&gt;
if ( 1 == 1.0 )&lt;br /&gt;
{&lt;br /&gt;
   print( &amp;quot;This line DOES get printed.&amp;quot; );&lt;br /&gt;
}&lt;br /&gt;
if ( 1 == 2 )&lt;br /&gt;
{&lt;br /&gt;
   print( &amp;quot;This line does NOT get printed.&amp;quot; );&lt;br /&gt;
}&lt;br /&gt;
if ( &amp;quot;Hello&amp;quot; == &amp;quot;hello&amp;quot; )&lt;br /&gt;
{&lt;br /&gt;
   print( &amp;quot;This line DOES get printed.&amp;quot; );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
==Boolean Operators==&lt;br /&gt;
{{&lt;br /&gt;
eztable|&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;&amp;amp;&amp;amp;&amp;lt;/nowiki&amp;gt; |and}}}}&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;||&amp;lt;/nowiki&amp;gt; |or}}}}&lt;br /&gt;
{{eztr|{{eztd| &amp;lt;nowiki&amp;gt;!&amp;lt;/nowiki&amp;gt; |not}}}}&lt;br /&gt;
}}&lt;br /&gt;
Note that the above operators only work with boolean values &amp;amp; datatypes. To make use of them with other datatypes, you will either need to first perform a [[Datatype Conversions|Datatype Conversion]], or you will need to nest your operations such that a boolean value is used with the boolean operators.&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
if ( true &amp;amp;&amp;amp; true )&lt;br /&gt;
{&lt;br /&gt;
   print( &amp;quot;This line DOES get printed (both possibilities proved true).&amp;quot; );&lt;br /&gt;
}&lt;br /&gt;
if ( true &amp;amp;&amp;amp; false )&lt;br /&gt;
{&lt;br /&gt;
   print( &amp;quot;This line does NOT get printed (only one possibility proved true).&amp;quot; );&lt;br /&gt;
}&lt;br /&gt;
if ( true || false )&lt;br /&gt;
{&lt;br /&gt;
   print( &amp;quot;This line DOES get printed (since at least one of the possibilities proved true).&amp;quot; );&lt;br /&gt;
}&lt;br /&gt;
if ( ! false )&lt;br /&gt;
{&lt;br /&gt;
   print( &amp;quot;This line DOES get printed (since the not operator converted false to true).&amp;quot; );&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;br /&gt;
We also need to understand operator precedence. Statements inside a () pair are always evaluated first, then from left to right.&lt;br /&gt;
{{&lt;br /&gt;
CodeSample|&lt;br /&gt;
code=&lt;br /&gt;
&amp;lt;syntaxhighlight&amp;gt;&lt;br /&gt;
if ( true || true &amp;amp;&amp;amp; false )&lt;br /&gt;
{&lt;br /&gt;
   print( &amp;quot;This line DOES get printed.&amp;quot; );&lt;br /&gt;
   // evaluated left-to-right&lt;br /&gt;
   // true or (true &amp;amp;&amp;amp; false) returns true&lt;br /&gt;
}&lt;br /&gt;
if ( true &amp;amp;&amp;amp; ( true &amp;amp;&amp;amp; false ) )&lt;br /&gt;
{&lt;br /&gt;
   print( &amp;quot;This line does NOT get printed.&amp;quot; );&lt;br /&gt;
   // ( true &amp;amp;&amp;amp; false ) is evaluated first since it is inside of parentheses&lt;br /&gt;
   // so we end up evaluating ( true &amp;amp;&amp;amp; false ) which returns false&lt;br /&gt;
}&lt;br /&gt;
if ( true &amp;amp;&amp;amp; ! ( true &amp;amp;&amp;amp; false ) )&lt;br /&gt;
{&lt;br /&gt;
   print( &amp;quot;This line DOES get printed.&amp;quot; );&lt;br /&gt;
   // ( true &amp;amp;&amp;amp; false ) is evaluated first since it is inside of parentheses&lt;br /&gt;
   // the ! operator converts the false from ( true &amp;amp;&amp;amp; false ) to true&lt;br /&gt;
   // ( true &amp;amp;&amp;amp; true ) returns true&lt;br /&gt;
}&lt;br /&gt;
&amp;lt;/syntaxhighlight&amp;gt;}}&lt;/div&gt;</summary>
		<author><name>68.157.42.151</name></author>
	</entry>
</feed>