<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="en">
	<id>https://wiki.harlamenkov.ru/index.php?action=history&amp;feed=atom&amp;title=EN%2Fdocumentation%2Fbasic_guide%2Fbranching</id>
	<title>EN/documentation/basic guide/branching - Revision history</title>
	<link rel="self" type="application/atom+xml" href="https://wiki.harlamenkov.ru/index.php?action=history&amp;feed=atom&amp;title=EN%2Fdocumentation%2Fbasic_guide%2Fbranching"/>
	<link rel="alternate" type="text/html" href="https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/branching&amp;action=history"/>
	<updated>2026-11-11T14:00:38Z</updated>
	<subtitle>Revision history for this page on the wiki</subtitle>
	<generator>MediaWiki 1.33.0</generator>
	<entry>
		<id>https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/branching&amp;diff=15887&amp;oldid=prev</id>
		<title>Sancho: Created page with &quot;&lt;section begin=title /&gt;&lt;noinclude&gt;{{DISPLAYTITLE:&lt;/noinclude&gt;Branching&lt;noinclude&gt;}}&lt;/noinclude&gt;&lt;section end=title /&gt;{{BreadCrumbL10n}}  {{Documentation/BASICGuideTOC |ShowPrevNex...&quot;</title>
		<link rel="alternate" type="text/html" href="https://wiki.harlamenkov.ru/index.php?title=EN/documentation/basic_guide/branching&amp;diff=15887&amp;oldid=prev"/>
		<updated>2011-09-01T14:28:08Z</updated>

		<summary type="html">&lt;p&gt;Created page with &amp;quot;&amp;lt;section begin=title /&amp;gt;&amp;lt;noinclude&amp;gt;{{DISPLAYTITLE:&amp;lt;/noinclude&amp;gt;Branching&amp;lt;noinclude&amp;gt;}}&amp;lt;/noinclude&amp;gt;&amp;lt;section end=title /&amp;gt;{{BreadCrumbL10n}}  {{Documentation/BASICGuideTOC |ShowPrevNex...&amp;quot;&lt;/p&gt;
&lt;p&gt;&lt;b&gt;New page&lt;/b&gt;&lt;/p&gt;&lt;div&gt;&amp;lt;section begin=title /&amp;gt;&amp;lt;noinclude&amp;gt;{{DISPLAYTITLE:&amp;lt;/noinclude&amp;gt;Branching&amp;lt;noinclude&amp;gt;}}&amp;lt;/noinclude&amp;gt;&amp;lt;section end=title /&amp;gt;{{BreadCrumbL10n}}&lt;br /&gt;
&lt;br /&gt;
{{Documentation/BASICGuideTOC&lt;br /&gt;
|ShowPrevNext=block&lt;br /&gt;
|ShowPrevPage=block&lt;br /&gt;
|PrevPage=EN/documentation/basic_guide/operators&lt;br /&gt;
|NextPage=EN/documentation/basic_guide/loops&lt;br /&gt;
|lang=block&lt;br /&gt;
}}&lt;br /&gt;
 &lt;br /&gt;
Use branching statements to restrict the execution of a code block until a particular condition is satisfied.&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;tt&amp;gt;If...Then...Else&amp;lt;/tt&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
The most common branching statement is the &amp;lt;tt&amp;gt;If&amp;lt;/tt&amp;gt; statement as shown in the following example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
If A &amp;gt; 3 Then&lt;br /&gt;
  B = 2&lt;br /&gt;
End If&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;B = 2&amp;lt;/tt&amp;gt; assignment only occurs when value of variable &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; is greater than three. A variation of the &amp;lt;tt&amp;gt;If&amp;lt;/tt&amp;gt; statement is the &amp;lt;tt&amp;gt;If/Else&amp;lt;/tt&amp;gt; clause:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
If A &amp;gt; 3 Then&lt;br /&gt;
  B = 2&lt;br /&gt;
Else&lt;br /&gt;
  B = 0&lt;br /&gt;
End If&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, the variable &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; is assigned the value of 2 when &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; is greater than 3, otherwise &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; is assigned the value of 0.&lt;br /&gt;
&lt;br /&gt;
For more complex statements, you can cascade the &amp;lt;tt&amp;gt;If&amp;lt;/tt&amp;gt; statement, for example:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
If A = 0 Then&lt;br /&gt;
  B = 0&lt;br /&gt;
ElseIf A &amp;lt; 3 Then&lt;br /&gt;
  B = 1&lt;br /&gt;
Else &lt;br /&gt;
  B = 2&lt;br /&gt;
End If&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
If the value of variable &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; equals zero, &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; is assigned the value 0. If &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; is less than 3 (but not equal to zero), then &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; is assigned the value 1. In all other instances (that is, if &amp;lt;tt&amp;gt;A&amp;lt;/tt&amp;gt; is greater than or equal to 3), &amp;lt;tt&amp;gt;B&amp;lt;/tt&amp;gt; is assigned the value 2.&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
A complete If statement may be written on a single line, with a simpler syntax. The first example of this page may be written as:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
If A &amp;gt; 3 Then  B = 2&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
The second example of this page may be written as:&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
If A &amp;gt; 3 Then  B = 2  Else  B = 0&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
== &amp;lt;tt&amp;gt;Select...Case&amp;lt;/tt&amp;gt; ==&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Select...Case&amp;lt;/tt&amp;gt; instruction is an alternative to the cascaded &amp;lt;tt&amp;gt;If&amp;lt;/tt&amp;gt; statement and is used when you need to check a value against various conditions:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Select Case DayOfWeek&lt;br /&gt;
  Case 1:&lt;br /&gt;
    NameOfWeekday = &amp;quot;Sunday&amp;quot;&lt;br /&gt;
  Case 2: &lt;br /&gt;
    NameOfWeekday = &amp;quot;Monday&amp;quot;&lt;br /&gt;
  Case 3: &lt;br /&gt;
    NameOfWeekday = &amp;quot;Tuesday&amp;quot;&lt;br /&gt;
  Case 4:&lt;br /&gt;
    NameOfWeekday = &amp;quot;Wednesday&amp;quot;&lt;br /&gt;
  Case 5:&lt;br /&gt;
    NameOfWeekday = &amp;quot;Thursday&amp;quot;&lt;br /&gt;
  Case 6:&lt;br /&gt;
    NameOfWeekday = &amp;quot;Friday&amp;quot;&lt;br /&gt;
  Case 7:&lt;br /&gt;
    NameOfWeekday = &amp;quot;Saturday&amp;quot;&lt;br /&gt;
End Select&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
In this example, the name of a weekday corresponds to a number, so that the &amp;lt;tt&amp;gt;DayOfWeek&amp;lt;/tt&amp;gt; variable is assigned the value of 1 for &amp;lt;tt&amp;gt;Sunday&amp;lt;/tt&amp;gt;, 2 for &amp;lt;tt&amp;gt;Monday&amp;lt;/tt&amp;gt; value, and so on.&lt;br /&gt;
&lt;br /&gt;
The &amp;lt;tt&amp;gt;Select&amp;lt;/tt&amp;gt; command is not restricted to simple 1:1 assignments — you can also specify comparison operators or lists of expressions in a &amp;lt;tt&amp;gt;Case&amp;lt;/tt&amp;gt; branch. The following example lists the most important syntax variants:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Select Case Var&lt;br /&gt;
  Case 1 To 5                   &lt;br /&gt;
    ' ... Var is between the numbers 1 and 5 (including the values 1 and 5).&lt;br /&gt;
  Case &amp;gt; 100&lt;br /&gt;
    ' ... Var is greater than 100&lt;br /&gt;
  Case 6, 7, 8                  &lt;br /&gt;
    ' ... Var is 6, 7 or 8&lt;br /&gt;
  Case 6, 7, 8, &amp;gt; 15, &amp;lt; 0&lt;br /&gt;
    ' ... Var is 6, 7, 8, greater than 15, or less than 0&lt;br /&gt;
  Case Else&lt;br /&gt;
    ' ... all other instances&lt;br /&gt;
End Select&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
Now consider a misleading (advanced) example, and a common error:&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Select Case Var&lt;br /&gt;
  Case Var = 8&lt;br /&gt;
    ' ... Var is 0&lt;br /&gt;
  Case Else&lt;br /&gt;
    ' ... all other instances&lt;br /&gt;
End Select&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
The statement (Var = 8) evaluates to TRUE if Var is 8, and FALSE otherwise. TRUE is -1 and FALSE is 0. The Select Case statement evaluates the expression, which is TRUE or FALSE, and then compares that value to Var. When Var is 0, there is a match. If you understand the last example, then you also know why this example does not do what it appears&lt;br /&gt;
&lt;br /&gt;
&amp;lt;source lang=&amp;quot;oobas&amp;quot;&amp;gt;&lt;br /&gt;
Select Case Var&lt;br /&gt;
  Case Var &amp;gt; 8 And Var &amp;lt; 11&lt;br /&gt;
    ' ... Var is 0&lt;br /&gt;
  Case Else&lt;br /&gt;
    ' ... all other instances&lt;br /&gt;
End Select&lt;br /&gt;
&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
{{PDL1}}&lt;/div&gt;</summary>
		<author><name>Sancho</name></author>
		
	</entry>
</feed>