<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ja">
	<id>https://wiki.macchky.net/index.php?action=history&amp;feed=atom&amp;title=%E5%88%B6%E5%BE%A1%E6%A7%8B%E6%96%87%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6</id>
	<title>制御構文について - 版の履歴</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.macchky.net/index.php?action=history&amp;feed=atom&amp;title=%E5%88%B6%E5%BE%A1%E6%A7%8B%E6%96%87%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6"/>
	<link rel="alternate" type="text/html" href="https://wiki.macchky.net/index.php?title=%E5%88%B6%E5%BE%A1%E6%A7%8B%E6%96%87%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6&amp;action=history"/>
	<updated>2026-05-10T14:45:45Z</updated>
	<subtitle>このウィキのこのページに関する変更履歴</subtitle>
	<generator>MediaWiki 1.34.0</generator>
	<entry>
		<id>https://wiki.macchky.net/index.php?title=%E5%88%B6%E5%BE%A1%E6%A7%8B%E6%96%87%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6&amp;diff=114&amp;oldid=prev</id>
		<title>2016年8月5日 (金) 01:13にMacchkyによる</title>
		<link rel="alternate" type="text/html" href="https://wiki.macchky.net/index.php?title=%E5%88%B6%E5%BE%A1%E6%A7%8B%E6%96%87%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6&amp;diff=114&amp;oldid=prev"/>
		<updated>2016-08-05T01:13:58Z</updated>

		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;col class=&quot;diff-marker&quot; /&gt;
				&lt;col class=&quot;diff-content&quot; /&gt;
				&lt;tr class=&quot;diff-title&quot; lang=&quot;ja&quot;&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;← 古い版&lt;/td&gt;
				&lt;td colspan=&quot;2&quot; style=&quot;background-color: #fff; color: #222; text-align: center;&quot;&gt;2016年8月5日 (金) 01:13時点における版&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot; id=&quot;mw-diff-left-l2&quot; &gt;2行目:&lt;/td&gt;
&lt;td colspan=&quot;2&quot; class=&quot;diff-lineno&quot;&gt;2行目:&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ソース：[https://community.bistudio.com/wiki/Control_Structures Control Structures - Bohemia Interactive Community]&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;ソース：[https://community.bistudio.com/wiki/Control_Structures Control Structures - Bohemia Interactive Community]&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt;−&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #ffe49c; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;&lt;del class=&quot;diffchange diffchange-inline&quot;&gt;Control Structures&lt;/del&gt;&amp;#039;&amp;#039;&amp;#039; are [[Statement|statements]] which are used to control execution flow in the scripts. They are sequences of scripting code which help to control complex procedures. You can use control structures to define code which is only executed under certain conditions or repeated for a couple of times.&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt;+&lt;/td&gt;&lt;td style=&quot;color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #a3d3ff; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#039;&amp;#039;&amp;#039;&lt;ins class=&quot;diffchange diffchange-inline&quot;&gt;制御構文&lt;/ins&gt;&amp;#039;&amp;#039;&amp;#039; are [[Statement|statements]] which are used to control execution flow in the scripts. They are sequences of scripting code which help to control complex procedures. You can use control structures to define code which is only executed under certain conditions or repeated for a couple of times.&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;/td&gt;&lt;/tr&gt;
&lt;tr&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#039;&amp;#039;Note for advanced readers: in OFP/ArmA/VBS scripting language control structures are normal scripting commands, with no special handling compared to other commands. This is different from most imperative programming languages (like C), where control statements are implemented in the core language grammar. The &amp;quot;controlling&amp;quot; done by them is implemented by accepting [[Code|code]] as an argument. The complex control structures like &amp;quot;[[while]] ... [[do]] ...&amp;quot; are implemented using helper types, like [[While Type]].&amp;#039;&amp;#039;&lt;/div&gt;&lt;/td&gt;&lt;td class=&#039;diff-marker&#039;&gt; &lt;/td&gt;&lt;td style=&quot;background-color: #f8f9fa; color: #222; font-size: 88%; border-style: solid; border-width: 1px 1px 1px 4px; border-radius: 0.33em; border-color: #eaecf0; vertical-align: top; white-space: pre-wrap;&quot;&gt;&lt;div&gt;&amp;#039;&amp;#039;Note for advanced readers: in OFP/ArmA/VBS scripting language control structures are normal scripting commands, with no special handling compared to other commands. This is different from most imperative programming languages (like C), where control statements are implemented in the core language grammar. The &amp;quot;controlling&amp;quot; done by them is implemented by accepting [[Code|code]] as an argument. The complex control structures like &amp;quot;[[while]] ... [[do]] ...&amp;quot; are implemented using helper types, like [[While Type]].&amp;#039;&amp;#039;&lt;/div&gt;&lt;/td&gt;&lt;/tr&gt;

&lt;!-- diff cache key wiki-mw:diff::1.12:old-113:rev-114 --&gt;
&lt;/table&gt;</summary>
		<author><name>Macchky</name></author>
		
	</entry>
	<entry>
		<id>https://wiki.macchky.net/index.php?title=%E5%88%B6%E5%BE%A1%E6%A7%8B%E6%96%87%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6&amp;diff=113&amp;oldid=prev</id>
		<title>Macchky: ページの作成:「Category:ARMA3Category:SQF ソース：[https://community.bistudio.com/wiki/Control_Structures Control Structures - Bohemia Interactive Community]  &#039;&#039;&#039;Control Str...」</title>
		<link rel="alternate" type="text/html" href="https://wiki.macchky.net/index.php?title=%E5%88%B6%E5%BE%A1%E6%A7%8B%E6%96%87%E3%81%AB%E3%81%A4%E3%81%84%E3%81%A6&amp;diff=113&amp;oldid=prev"/>
		<updated>2016-08-04T22:52:13Z</updated>

		<summary type="html">&lt;p&gt;ページの作成:「&lt;a href=&quot;/view/%E3%82%AB%E3%83%86%E3%82%B4%E3%83%AA:ARMA3&quot; title=&quot;カテゴリ:ARMA3&quot;&gt;Category:ARMA3&lt;/a&gt;&lt;a href=&quot;/index.php?title=%E3%82%AB%E3%83%86%E3%82%B4%E3%83%AA:SQF&amp;amp;action=edit&amp;amp;redlink=1&quot; class=&quot;new&quot; title=&quot;カテゴリ:SQF (存在しないページ)&quot;&gt;Category:SQF&lt;/a&gt; ソース：[https://community.bistudio.com/wiki/Control_Structures Control Structures - Bohemia Interactive Community]  &amp;#039;&amp;#039;&amp;#039;Control Str...」&lt;/p&gt;
&lt;p&gt;&lt;b&gt;新規ページ&lt;/b&gt;&lt;/p&gt;&lt;div&gt;[[Category:ARMA3]][[Category:SQF]]&lt;br /&gt;
ソース：[https://community.bistudio.com/wiki/Control_Structures Control Structures - Bohemia Interactive Community]&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Control Structures&amp;#039;&amp;#039;&amp;#039; are [[Statement|statements]] which are used to control execution flow in the scripts. They are sequences of scripting code which help to control complex procedures. You can use control structures to define code which is only executed under certain conditions or repeated for a couple of times.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;Note for advanced readers: in OFP/ArmA/VBS scripting language control structures are normal scripting commands, with no special handling compared to other commands. This is different from most imperative programming languages (like C), where control statements are implemented in the core language grammar. The &amp;quot;controlling&amp;quot; done by them is implemented by accepting [[Code|code]] as an argument. The complex control structures like &amp;quot;[[while]] ... [[do]] ...&amp;quot; are implemented using helper types, like [[While Type]].&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
== Requirements ==&lt;br /&gt;
&lt;br /&gt;
To fully understand this article you should read the following articles:&lt;br /&gt;
&lt;br /&gt;
* [[ArmA: Introduction to Scripting]]&lt;br /&gt;
* [[Variables]]&lt;br /&gt;
* [[Operators]]&lt;br /&gt;
&lt;br /&gt;
== Conditional Structures ==&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Conditional structures&amp;#039;&amp;#039;&amp;#039; help to define code which is only executed under certain circumstances. Often you will write code that depends on the game state, on other code or other conditions.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;[[if]]&amp;lt;/tt&amp;gt;-Statement ===&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;if&amp;lt;/tt&amp;gt;-statement defines code that is only executed &amp;#039;&amp;#039;&amp;#039;if&amp;#039;&amp;#039;&amp;#039; a certain condition is met. The syntax of it looks like that:&lt;br /&gt;
&lt;br /&gt;
 if (CONDITION) then&lt;br /&gt;
 {&lt;br /&gt;
     STATEMENT;&lt;br /&gt;
     ...&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;CONDITION&amp;lt;/tt&amp;gt; is a [[Boolean]] [[Statement|statement]] or [[Variables|variable]] which returns either &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt; or &amp;lt;tt&amp;gt;false&amp;lt;/tt&amp;gt;. The code nested in the following [[Block|block]] is only executed if the condition is &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt;, else ignored.&lt;br /&gt;
* &amp;lt;tt&amp;gt;STATEMENT&amp;lt;/tt&amp;gt; is a custom sequence of [[Statement|statements]]. That may be commands, assignments, control structures etc.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 [[if]] (_temperature &amp;lt; 0) [[then]]&lt;br /&gt;
 {&lt;br /&gt;
     [[hint]] &amp;quot;Snow!&amp;quot;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
In this example, first the value of &amp;lt;tt&amp;gt;_temperature&amp;lt;/tt&amp;gt; is checked:&lt;br /&gt;
&lt;br /&gt;
* If the value is 0 or greater than 0, the nested code is ignored.&lt;br /&gt;
* If the value is less than 0, the command &amp;lt;tt&amp;gt;hint &amp;quot;Snow!&amp;quot;;&amp;lt;/tt&amp;gt; is executed.&lt;br /&gt;
&lt;br /&gt;
==== Alternative Code ([[else]])====&lt;br /&gt;
&lt;br /&gt;
You can also define &amp;#039;&amp;#039;alternative&amp;#039;&amp;#039; code that is executed, when the condition is &amp;#039;&amp;#039;not&amp;#039;&amp;#039; &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 if (CONDITION) then&lt;br /&gt;
 {&lt;br /&gt;
     STATEMENT;&lt;br /&gt;
     ...&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
     STATEMENT;&lt;br /&gt;
     ...&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
Here you have a second sequence of [[Statement|statements]] executed when &amp;lt;tt&amp;gt;CONDITION&amp;lt;/tt&amp;gt; is &amp;lt;tt&amp;gt;false&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
==== Conditional assignments ====&lt;br /&gt;
If...then structures can also be used to assign conditional values to variables:&lt;br /&gt;
&amp;lt;code&amp;gt;_living = if (alive player) then {true} else {false};&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
==== SQS syntax (deprecated) ====&lt;br /&gt;
&lt;br /&gt;
Within [[SQS syntax]] the use of [[goto]] labels is a way to execute more than one statement within if...then structures.&lt;br /&gt;
&lt;br /&gt;
 [[if]] (CONDITION) [[then]] {[[goto]] &amp;quot;label&amp;quot;}&lt;br /&gt;
 ... some other statements&lt;br /&gt;
 #label&lt;br /&gt;
   statement1&lt;br /&gt;
   statement2&lt;br /&gt;
   statement3&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example 1: (without [[else]])&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 [[if]] (_temperature &amp;lt; 0) [[then]] {[[goto]] &amp;quot;Snow&amp;quot;}&lt;br /&gt;
 ... some other statements&lt;br /&gt;
 #Snow&lt;br /&gt;
   [[hint]] &amp;quot;Snow!&amp;quot;&lt;br /&gt;
   [[echo]] &amp;quot;There is snow!&amp;quot;&lt;br /&gt;
   variable = [[text]] &amp;quot;Hey. Snow outside.&amp;quot;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example 2: (with [[else]])&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 [[if]] (_temperature &amp;lt; 0) [[then]] {[[goto]] &amp;quot;Snow&amp;quot;} [[else]] {[[goto]] &amp;quot;Sunshine&amp;quot;}&lt;br /&gt;
 ... some other statements&lt;br /&gt;
 Goto &amp;quot;Continue&amp;quot;&lt;br /&gt;
 #Snow&lt;br /&gt;
   [[hint]] &amp;quot;Snow!&amp;quot;&lt;br /&gt;
   [[echo]] &amp;quot;There is snow!&amp;quot;&lt;br /&gt;
   variable = [[text]] &amp;quot;Hey. Snow outside.&amp;quot;&lt;br /&gt;
   Goto &amp;quot;Continue&amp;quot;&lt;br /&gt;
 #Sunshine&lt;br /&gt;
   [[hint]] &amp;quot;No Snow but sunshine!&amp;quot;&lt;br /&gt;
   [[echo]] &amp;quot;There is no snow!&amp;quot;&lt;br /&gt;
   variable = [[text]] &amp;quot;Hey. No snow outside.&amp;quot;&lt;br /&gt;
   Goto &amp;quot;Continue&amp;quot;&lt;br /&gt;
 #Continue&lt;br /&gt;
  ...&lt;br /&gt;
&lt;br /&gt;
==== Nested &amp;lt;tt&amp;gt;if&amp;lt;/tt&amp;gt;-Statements ====&lt;br /&gt;
&lt;br /&gt;
Since the &amp;lt;tt&amp;gt;if&amp;lt;/tt&amp;gt;-statement is itself a [[Statement|statement]], you can also create &amp;#039;&amp;#039;&amp;#039;nested &amp;lt;tt&amp;gt;if&amp;lt;/tt&amp;gt;-statements&amp;#039;&amp;#039;&amp;#039;.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 if ([[alive]] [[player]]) then&lt;br /&gt;
 {&lt;br /&gt;
     if ([[someAmmo]] [[player]]) then&lt;br /&gt;
     {&lt;br /&gt;
         [[hint]] &amp;quot;The player is alive and has ammo!&amp;quot;;&lt;br /&gt;
     }&lt;br /&gt;
     else&lt;br /&gt;
     {&lt;br /&gt;
         [[hint]] &amp;quot;The player is out of ammo!&amp;quot;;&lt;br /&gt;
     };&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
     [[hint]] &amp;quot;The player is dead!&amp;quot;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;[[switch]]&amp;lt;/tt&amp;gt;-Statement ===&lt;br /&gt;
&lt;br /&gt;
([[Armed Assault]] and [[VBS2]] only)&lt;br /&gt;
&lt;br /&gt;
In some cases you may want to check a [[Variables|variable]] for several values and execute different code depending on the value. With the above knowledge you could just write a sequence of &amp;lt;tt&amp;gt;if&amp;lt;/tt&amp;gt;-statements.&lt;br /&gt;
&lt;br /&gt;
 if (_color == &amp;quot;blue&amp;quot;) then&lt;br /&gt;
 {&lt;br /&gt;
     hint &amp;quot;What a nice color&amp;quot;;&lt;br /&gt;
 }&lt;br /&gt;
 else&lt;br /&gt;
 {&lt;br /&gt;
     if (_color == &amp;quot;red&amp;quot;) then&lt;br /&gt;
     {&lt;br /&gt;
         hint &amp;quot;Don&amp;#039;t you get aggressive?&amp;quot;;&lt;br /&gt;
     }&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
The more values you want to compare, the longer gets this sequence. That is why the simplified &amp;lt;tt&amp;gt;switch&amp;lt;/tt&amp;gt;-statement was introduced.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;switch&amp;lt;/tt&amp;gt;-statement compares a variable against different values:&lt;br /&gt;
&lt;br /&gt;
 switch (VARIABLE) do&lt;br /&gt;
 {&lt;br /&gt;
     case VALUE1:&lt;br /&gt;
     {&lt;br /&gt;
         STATEMENT;&lt;br /&gt;
         ...&lt;br /&gt;
     };&lt;br /&gt;
 &lt;br /&gt;
     case VALUE2:&lt;br /&gt;
     {&lt;br /&gt;
         STATEMENT;&lt;br /&gt;
         ...&lt;br /&gt;
     };&lt;br /&gt;
 &lt;br /&gt;
     ...&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
The structure compares &amp;lt;tt&amp;gt;VARIABLE&amp;lt;/tt&amp;gt; against all given values (&amp;lt;tt&amp;gt;VALUE1&amp;lt;/tt&amp;gt;, &amp;lt;tt&amp;gt;VALUE2&amp;lt;/tt&amp;gt;, ...). If any of the values matches, the corresponding block of statements is executed.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 switch (_color) do&lt;br /&gt;
 {&lt;br /&gt;
     case &amp;quot;blue&amp;quot;:&lt;br /&gt;
     {&lt;br /&gt;
         hint &amp;quot;What a nice color&amp;quot;;&lt;br /&gt;
     };&lt;br /&gt;
 &lt;br /&gt;
     case &amp;quot;red&amp;quot;:&lt;br /&gt;
     {&lt;br /&gt;
         hint &amp;quot;Don&amp;#039;t you get aggressive?&amp;quot;;&lt;br /&gt;
     };&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;tt&amp;gt;default&amp;lt;/tt&amp;gt;-Block ====&lt;br /&gt;
&lt;br /&gt;
In some cases you may want to define alternative code that is executed, when none of the values matches. You can write this code in a &amp;lt;tt&amp;gt;default&amp;lt;/tt&amp;gt;-Block. Note that there is &amp;#039;&amp;#039;&amp;#039;no colon&amp;#039;&amp;#039;&amp;#039; after the &amp;lt;tt&amp;gt;default&amp;lt;/tt&amp;gt; tag!&lt;br /&gt;
&lt;br /&gt;
 switch (VARIABLE) do&lt;br /&gt;
 {&lt;br /&gt;
     case VALUE1:&lt;br /&gt;
     {&lt;br /&gt;
         STATEMENT;&lt;br /&gt;
         ...&lt;br /&gt;
     };&lt;br /&gt;
 &lt;br /&gt;
     case VALUE2:&lt;br /&gt;
     {&lt;br /&gt;
         STATEMENT;&lt;br /&gt;
         ...&lt;br /&gt;
     };&lt;br /&gt;
 &lt;br /&gt;
     ...&lt;br /&gt;
 &lt;br /&gt;
     default&lt;br /&gt;
     {&lt;br /&gt;
         STATEMENT;&lt;br /&gt;
         ...&lt;br /&gt;
     };&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
==== variable assignments ====&lt;br /&gt;
Switch can be used to assign different values to a variable:&lt;br /&gt;
&amp;lt;code&amp;gt;_color=switch (side player) do {case west: {&amp;quot;ColorGreen&amp;quot;}; case east: {&amp;quot;ColorRed&amp;quot;}; };&amp;lt;/code&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== Loops ==&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Loops&amp;#039;&amp;#039;&amp;#039; are used to execute the same [[Block|code block]] for a specific or unspecific number of times.&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;[[while]]&amp;lt;/tt&amp;gt;-Loop ===&lt;br /&gt;
This loop repeats the same code block as long as a given [[boolean]] condition is &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt;.&lt;br /&gt;
&lt;br /&gt;
 while {CONDITION} do&lt;br /&gt;
 {&lt;br /&gt;
     STATEMENT;&lt;br /&gt;
     ...&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
Note the &amp;#039;&amp;#039;&amp;#039;curled braces&amp;#039;&amp;#039;&amp;#039; for the condition. The loop processes as follow:&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;tt&amp;gt;CONDITION&amp;lt;/tt&amp;gt; is evaluated. If it is &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt;, go on to 2., else skip the block and go on with the code following the loop.&lt;br /&gt;
# Execution of all nested [[Statement|statements]]. Go back to 1.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;tt&amp;gt;CONDITION&amp;lt;/tt&amp;gt; is &amp;lt;tt&amp;gt;false&amp;lt;/tt&amp;gt; from the beginning on, the statements within the block of the loop will never be executed.&lt;br /&gt;
&lt;br /&gt;
Because the test of the while expression takes place before each execution of the loop, a while loop executes zero or more times.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 _counter = 0;&lt;br /&gt;
 &lt;br /&gt;
 while {_counter &amp;lt; 10} do&lt;br /&gt;
 {&lt;br /&gt;
     _counter = _counter + 1;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;[[for]]&amp;lt;/tt&amp;gt;-Loop ===&lt;br /&gt;
&lt;br /&gt;
(not available in [[OFP]])&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt;-loop repeats the same code block for a specific number of times.&lt;br /&gt;
&lt;br /&gt;
 for [{BEGIN}, {CONDITION}, {STEP}] do&lt;br /&gt;
 {&lt;br /&gt;
     STATEMENT;&lt;br /&gt;
     ...&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;BEGIN&amp;lt;/tt&amp;gt; is a number of [[Statement|statements]] executed &amp;#039;&amp;#039;before&amp;#039;&amp;#039; the loop starts&lt;br /&gt;
* &amp;lt;tt&amp;gt;CONDITION&amp;lt;/tt&amp;gt; is a [[Boolean]] [[condition]] evaluated &amp;#039;&amp;#039;before&amp;#039;&amp;#039; each loop&lt;br /&gt;
* &amp;lt;tt&amp;gt;STEP&amp;lt;/tt&amp;gt; is a number of statements executed &amp;#039;&amp;#039;after&amp;#039;&amp;#039; each loop&lt;br /&gt;
&lt;br /&gt;
The loop processes as follows:&lt;br /&gt;
&lt;br /&gt;
# &amp;lt;tt&amp;gt;BEGIN&amp;lt;/tt&amp;gt; is executed&lt;br /&gt;
# &amp;lt;tt&amp;gt;CONDITION&amp;lt;/tt&amp;gt; is evaluated. If it is &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt;, go on to 3., else skip the block and go on with the code following the loop.&lt;br /&gt;
# The statements in the code block are executed&lt;br /&gt;
# &amp;lt;tt&amp;gt;STEP&amp;lt;/tt&amp;gt; is executed, go on to 2.&lt;br /&gt;
&lt;br /&gt;
If &amp;lt;tt&amp;gt;CONDITION&amp;lt;/tt&amp;gt; is &amp;lt;tt&amp;gt;false&amp;lt;/tt&amp;gt; from the beginning on, the code block will never be executed.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 // a loop repeating 10 times&lt;br /&gt;
 for [{_i=0}, {_i&amp;lt;10}, {_i=_i+1}] do&lt;br /&gt;
 {&lt;br /&gt;
     player globalChat format&amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;&amp;quot;%1&amp;quot;,_i&amp;lt;nowiki&amp;gt;]&amp;lt;/nowiki&amp;gt;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
will display&lt;br /&gt;
&lt;br /&gt;
 0&lt;br /&gt;
 1&lt;br /&gt;
 2&lt;br /&gt;
 3&lt;br /&gt;
 4&lt;br /&gt;
 5&lt;br /&gt;
 6&lt;br /&gt;
 7&lt;br /&gt;
 8&lt;br /&gt;
 9&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Description:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# The variable &amp;lt;tt&amp;gt;_i&amp;lt;/tt&amp;gt; is set to 0&lt;br /&gt;
# The condition &amp;lt;tt&amp;gt;_i&amp;lt;10&amp;lt;/tt&amp;gt; is evaluated, which is &amp;lt;tt&amp;gt;true&amp;lt;/tt&amp;gt; until &amp;lt;tt&amp;gt;_i&amp;lt;/tt&amp;gt; surpasses 9.&lt;br /&gt;
# The code &amp;lt;tt&amp;gt;player globalChat _i;&amp;lt;/tt&amp;gt; is executed&lt;br /&gt;
# The variable &amp;lt;tt&amp;gt;_i&amp;lt;/tt&amp;gt; is incremented by 1, back to step 2.&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt;-&amp;lt;tt&amp;gt;from&amp;lt;/tt&amp;gt;-&amp;lt;tt&amp;gt;to&amp;lt;/tt&amp;gt;-Loop ====&lt;br /&gt;
&lt;br /&gt;
There exists an alternate syntax of the &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt;-loop, which simplifies the last example a bit.&lt;br /&gt;
&lt;br /&gt;
 for &amp;quot;VARNAME&amp;quot; from STARTVALUE to ENDVALUE do&lt;br /&gt;
 {&lt;br /&gt;
     STATEMENT;&lt;br /&gt;
     ...&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;VARNAME&amp;lt;/tt&amp;gt; is any name given to the variable used to count the loop&lt;br /&gt;
* &amp;lt;tt&amp;gt;STARTVALUE&amp;lt;/tt&amp;gt; is a [[Number]] value given to the counter variable before the loop starts&lt;br /&gt;
* &amp;lt;tt&amp;gt;ENDVALUE&amp;lt;/tt&amp;gt; is a [[Number]] value until which the counter is incremented/decremented&lt;br /&gt;
&lt;br /&gt;
The loop processes as follows:&lt;br /&gt;
&lt;br /&gt;
#A variable with the name &amp;lt;tt&amp;gt;VARNAME&amp;lt;/tt&amp;gt; is initialized with &amp;lt;tt&amp;gt;STARTVALUE&amp;lt;/tt&amp;gt;&lt;br /&gt;
#If &amp;lt;tt&amp;gt;VARNAME&amp;lt;/tt&amp;gt; is not equal to &amp;lt;tt&amp;gt;ENDVALUE&amp;lt;/tt&amp;gt;, the code block is executed&lt;br /&gt;
#&lt;br /&gt;
##If &amp;lt;tt&amp;gt;ENDVALUE&amp;lt;/tt&amp;gt; is greater than &amp;lt;tt&amp;gt;STARTVALUE&amp;lt;/tt&amp;gt;, the variable &amp;lt;tt&amp;gt;VARNAME&amp;lt;/tt&amp;gt; is incremented by 1&lt;br /&gt;
##If &amp;lt;tt&amp;gt;ENDVALUE&amp;lt;/tt&amp;gt; is less than &amp;lt;tt&amp;gt;STARTVALUE&amp;lt;/tt&amp;gt;, the variable &amp;lt;tt&amp;gt;VARNAME&amp;lt;/tt&amp;gt; is decremented by 1&lt;br /&gt;
#Go back to step 2&lt;br /&gt;
&lt;br /&gt;
The following example is semantically equal to the last example.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 // a loop repeating 10 times&lt;br /&gt;
 for &amp;quot;_i&amp;quot; from 0 to 9 do&lt;br /&gt;
 {&lt;br /&gt;
     player globalChat format&amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;&amp;quot;%1&amp;quot;,_i&amp;lt;nowiki&amp;gt;]&amp;lt;/nowiki&amp;gt;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Description:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
#&amp;lt;tt&amp;gt;_i&amp;lt;/tt&amp;gt; is set to 0&lt;br /&gt;
#&amp;lt;tt&amp;gt;player globalChat 0&amp;lt;/tt&amp;gt; is executed&lt;br /&gt;
#&amp;lt;tt&amp;gt;_i&amp;lt;/tt&amp;gt; is incremented by 1 =&amp;gt; &amp;lt;tt&amp;gt;_i&amp;lt;/tt&amp;gt; is now 1&lt;br /&gt;
#Back to step 2&lt;br /&gt;
&lt;br /&gt;
==== &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt;-&amp;lt;tt&amp;gt;from&amp;lt;/tt&amp;gt;-&amp;lt;tt&amp;gt;to&amp;lt;/tt&amp;gt;-Loop with custom &amp;lt;tt&amp;gt;step&amp;lt;/tt&amp;gt; ====&lt;br /&gt;
&lt;br /&gt;
The default step to increment the variable in &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt;-&amp;lt;tt&amp;gt;from&amp;lt;/tt&amp;gt;-&amp;lt;tt&amp;gt;to&amp;lt;/tt&amp;gt;-Loops is 1. You can set a custom step though using this syntax:&lt;br /&gt;
&lt;br /&gt;
 for &amp;quot;VARNAME&amp;quot; from STARTVALUE to ENDVALUE step STEP do&lt;br /&gt;
 {&lt;br /&gt;
     STATEMENT;&lt;br /&gt;
     ...&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
* &amp;lt;tt&amp;gt;STEP&amp;lt;/tt&amp;gt; is a [[Number]] which defines the step by which the variable is incremented every loop&lt;br /&gt;
&lt;br /&gt;
The rest is equal to the above section.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 // a loop repeating 5 times&lt;br /&gt;
 for &amp;quot;_i&amp;quot; from 0 to 9 step 2 do&lt;br /&gt;
 {&lt;br /&gt;
     player globalChat format&amp;lt;nowiki&amp;gt;[&amp;lt;/nowiki&amp;gt;&amp;quot;%1&amp;quot;,_i&amp;lt;nowiki&amp;gt;]&amp;lt;/nowiki&amp;gt;;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Description:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
#&amp;lt;tt&amp;gt;_i&amp;lt;/tt&amp;gt; is set to 0&lt;br /&gt;
#&amp;lt;tt&amp;gt;player globalChat 0&amp;lt;/tt&amp;gt; is executed&lt;br /&gt;
#&amp;lt;tt&amp;gt;_i&amp;lt;/tt&amp;gt; is incremented by 2 =&amp;gt; &amp;lt;tt&amp;gt;_i&amp;lt;/tt&amp;gt; is now 2&lt;br /&gt;
#Back to step 2&lt;br /&gt;
&lt;br /&gt;
=== &amp;lt;tt&amp;gt;[[forEach]]&amp;lt;/tt&amp;gt;-Loop ===&lt;br /&gt;
&lt;br /&gt;
You will often use the &amp;lt;tt&amp;gt;for&amp;lt;/tt&amp;gt;-loop to increment over [[Array|arrays]].&lt;br /&gt;
&lt;br /&gt;
 _array = [unit1, unit2, unit3];&lt;br /&gt;
 &lt;br /&gt;
 for [{_i=0}, {_i &amp;lt; count _array}, {_i=_i+1}] do&lt;br /&gt;
 {&lt;br /&gt;
     (_array select _i) setDamage 1;&lt;br /&gt;
 };&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;forEach&amp;lt;/tt&amp;gt;-loop does exactly that: It repeats the same code block for every item in an array.&lt;br /&gt;
&lt;br /&gt;
 {&lt;br /&gt;
     STATEMENT;&lt;br /&gt;
     ...&lt;br /&gt;
 }&lt;br /&gt;
 forEach ARRAY;&lt;br /&gt;
&lt;br /&gt;
The code block is executed exactly &amp;lt;tt&amp;gt;([[count]] ARRAY)&amp;lt;/tt&amp;gt; times.&lt;br /&gt;
&lt;br /&gt;
You may use the [[Magic Variables|magic variable]] &amp;lt;tt&amp;gt;_x&amp;lt;/tt&amp;gt; within the code block, which always references to the current item of the array.&lt;br /&gt;
Magic variable &amp;lt;tt&amp;gt;_foreachindex&amp;lt;/tt&amp;gt; contains current index of the _x element in ARRAY.&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 _array = [unit1, unit2, unit3];&lt;br /&gt;
 &lt;br /&gt;
 {&lt;br /&gt;
     _x setDamage 1;&lt;br /&gt;
 }&lt;br /&gt;
 forEach _array;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Description:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
# In the first loop, the statement &amp;lt;tt&amp;gt;unit1 setDamage 1;&amp;lt;/tt&amp;gt; is executed&lt;br /&gt;
# In the second loop, the statement &amp;lt;tt&amp;gt;unit2 setDamage 1;&amp;lt;/tt&amp;gt; is executed&lt;br /&gt;
# In the third loop, the statement &amp;lt;tt&amp;gt;unit3 setDamage 1;&amp;lt;/tt&amp;gt; is executed&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;NOTE: Each iteration (also when it consists of plural commands) will be executed within one frame, so be aware of large and/or complex code blocks!&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
== Return Values ==&lt;br /&gt;
&lt;br /&gt;
Control structures always return the &amp;#039;&amp;#039;&amp;#039;last [[expression]] evaluated&amp;#039;&amp;#039;&amp;#039; within the structure.&lt;br /&gt;
&amp;lt;!-- Note that there &amp;#039;&amp;#039;&amp;#039;must not&amp;#039;&amp;#039;&amp;#039; be a semicolon (;) after this value, otherwise [[Nothing]] is returned. --&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;&amp;lt;!-- Correct --&amp;gt; example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 if (myCondition) then {myValueA} else {myValueB};&lt;br /&gt;
 &lt;br /&gt;
 =&amp;gt; returns myValueA or myValueB&lt;br /&gt;
&amp;lt;!--&lt;br /&gt;
&amp;#039;&amp;#039;&amp;#039;Incorrect example:&amp;#039;&amp;#039;&amp;#039;&lt;br /&gt;
&lt;br /&gt;
 if (myCondition) then {myValueA;} else {myValueB;};&lt;br /&gt;
 &lt;br /&gt;
 =&amp;gt; returns [[Nothing]]&lt;br /&gt;
--&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== See also ==&lt;br /&gt;
&lt;br /&gt;
* [[Statement]]&lt;br /&gt;
* [[Expression]]&lt;/div&gt;</summary>
		<author><name>Macchky</name></author>
		
	</entry>
</feed>