Difference between revisions of "Control:If..Else"

From Lavish Software Wiki
Jump to navigation Jump to search
Line 34: Line 34:
  
 
== See Also ==
 
== See Also ==
*[[LavishScript:Script Development|Script Development]]
+
*[[LavishScript:Language_and_Engine_Overview|Language_and_Engine_Overview]]
*[[LavishScript:Script Development#Control Structures|Control Structures]]
+
*[[LavishScript:Language_and_Engine_Overview#Control Structures|Control Structures]]
 
*[[LavishScript:Commands|Commands]]
 
*[[LavishScript:Commands|Commands]]
 
*[[LavishScript:Mathematical Formulae|Mathematical Formulae]]
 
*[[LavishScript:Mathematical Formulae|Mathematical Formulae]]
  
[[Category:LavishScript]] [[Category:LavishScript Commands]]
+
[[Category:LavishScript]] [[Category:LavishScript Control Structures]]

Revision as of 04:46, 16 May 2006

Forms

If

if <formula>
  <command or code block>

This form will conditionally execute the following command or code block. The command or code block must begin on the following line. The command or code block will be executed if the result of the calculation is not equal to zero (0), which means it will be skipped if the result of the calculation is equal to zero (0).

If-Else

if <formula>
  <command or code block>
else
  <command or code block>

This form extends the previous form by adding a second command or code block, which executes only when the first one does not execute. This literally means "if something, then do this, otherwise do that".

If-Elseif

if <formula>
  <command or code block>
elseif <formula>
  <command or code block>

This form also extends the original form by adding a second command or code block, which is similar to else, but checks an additional condition before executing the new command or code block. This literally means "if something, then do this; if not, then if something else, do that". Elseif may be chained and eventually followed up with Else.

Examples

 if x == 5
 {
   if y == 6
     z:Set[17]
 }
 elseif x == 6
   z:Set[10]
 else
 {
   y:Set[4]
   z:Set[26]
 }

See Also