Difference between revisions of "If"

From Wiki
Jump to: navigation, search
(Synopsis)
Line 1: Line 1:
__NOTOC__
+
{{command header|Flow Control}}
== if ==
+
{{body|if ( expression ) { }|The ''if'' construct is one of the most important feature of many languages, the EasyUO scripting language included. It allows for conditional execution of code fragments.
'''Flow Control'''
+
=== Synopsis ===
+
[[if]] ( ''expression'' ) [lines]
+
  
statement
+
As described in the section about expressions ''expression'' is evaluated to its boolean value. If it evaluates to [[true]] the statement will be executed.
 
+
<b>OR</b>
+
 
+
[[if]] ( ''expression'' )
+
 
+
{
+
 
+
statements
+
 
+
}
+
 
+
=== Description ===
+
The [[if]] construct is one of the most important feature of many languages, the EasyUO scripting language included. It allows for conditional execution of code fragments.
+
 
+
As described in the section about expressions ''expression'' is evaluated to its boolean value. If it evaluates to [[#true]] the statement will be executed.
+
  
 
The following code fragment will display <b>a is bigger than b</b> if %a is bigger than %b:
 
The following code fragment will display <b>a is bigger than b</b> if %a is bigger than %b:
Line 39: Line 21:
 
}
 
}
 
</pre>
 
</pre>
[[if]] statements can be nested indefinitely within other [[if]] statements, which provides you with complete flexibility for conditional execution of the various parts of your script.
+
''if'' statements can be nested indefinitely within other [[if]] statements, which provides you with complete flexibility for conditional execution of the various parts of your script.}}
  
 
==== Example ====
 
==== Example ====
Line 50: Line 32:
 
</pre>
 
</pre>
  
=== See Also ===
+
{{footer}}
{|
+
| Width=200px | [[else]]
+
|}
+
----
+
{|
+
| Width=200px | [[Main_Page]] || Width=200px | [[Documentation]] || Width=200px |
+
[[Documentation#Flow_Control|Flow Control]]
+
|}
+

Revision as of 09:38, 27 August 2005

Synopsis

if ( expression ) { }

Description

The if construct is one of the most important feature of many languages, the EasyUO scripting language included. It allows for conditional execution of code fragments.

As described in the section about expressions expression is evaluated to its boolean value. If it evaluates to true the statement will be executed.

The following code fragment will display a is bigger than b if %a is bigger than %b:

set %a 1
set %b 0
if %a > %b
	display ok a is bigger than b

Often you would want to have more than one statement executed conditionally. Of course, there is no need to wrap each statement in an if clause. Instead, you can group several statements into a statement group. For example, this code would display a is bigger than b if %a is bigger than %b, and would then assign the value of %a into %b:

set %a 10
set %b 2
if %a > %b
{
	display ok a is bigger than b
	set %b %a
}

if statements can be nested indefinitely within other if statements, which provides you with complete flexibility for conditional execution of the various parts of your script.

Example

if #charposx > #charposy
{
	display ok You are farther East than you are South!
	halt
}

See also

Main Page Documentation