Difference between revisions of "If"

From the Oblivion ConstructionSet Wiki
Jump to navigation Jump to search
imported>JOG
imported>Simetrical
m (Reformat)
Line 1: Line 1:
Oblivion's "IF"-command is very powerful and comparable to "real" programming languages. The expressions to test on can be very complex:
Oblivion's <tt>if</tt> command is very powerful and comparable to "real" programming languages. The expressions to test on can be very complex:


Assuming "a = 17", "b = 20" and "c = a - b", all of the following expressions work as expected.  Parentheses are only needed when they're necessary for mathematical reasons.


Assuming, "a = 17", "b = 20" and "c = a - b", all of the following expressions work fine, and parentheses are only needed when they're necessary out of mathematical reasons:
IF c == -3 && b == 20
IF c == -3 && b == 20 && a == 17
IF c - 1 == -4 && b == 20 && a == 17
IF a - 20 == 17 - b
IF a - 20 == 17 - b && c + 3 == 0
IF a + 3 == b
IF a - b == c
IF a *4 - b * 4 == c * 4
If a * ( 5 + c ) - 14 == b
If 2*(a*(5+c)-14)==b - -b


'''IF c == -3 && b == 20'''
Note that the && and || operators are logical only, and cannot be used for bitwise comparison.  E.g.:


'''IF c == -3 && b == 20 && a == 17'''
IF a && 16


'''IF c - 1 == -4 && b == 20 && a == 17'''
This will be true as long as a != 0.


'''IF a - 20 == 17 - b'''
[[Category:Commands]]
 
'''IF a - 20 == 17 - b && c + 3 == 0'''
 
'''IF a + 3 == b'''
 
'''IF a - b == c'''
 
'''IF a *4 - b * 4 == c * 4'''
 
'''If a * ( 5 + c ) - 14 == b'''
 
'''If 2*(a*(5+c)-14)==b - -b'''
 
 
What doesn't work is using the && and || operators for bitwise comparsion:
 
'''IF a && 16'''
 
 
this will allways be true, as long as a != 0
 
[[Category: Commands]]

Revision as of 20:18, 4 April 2006

Oblivion's if command is very powerful and comparable to "real" programming languages. The expressions to test on can be very complex:

Assuming "a = 17", "b = 20" and "c = a - b", all of the following expressions work as expected. Parentheses are only needed when they're necessary for mathematical reasons.

IF c == -3 && b == 20
IF c == -3 && b == 20 && a == 17
IF c - 1 == -4 && b == 20 && a == 17
IF a - 20 == 17 - b
IF a - 20 == 17 - b && c + 3 == 0
IF a + 3 == b
IF a - b == c
IF a *4 - b * 4 == c * 4
If a * ( 5 + c ) - 14 == b
If 2*(a*(5+c)-14)==b - -b

Note that the && and || operators are logical only, and cannot be used for bitwise comparison. E.g.:

IF a && 16

This will be true as long as a != 0.