"Sputnik" help |

Sputnik
Help

Booleans

Booleans are logical values. Only two Boolean values exist: **true**
and **false**.

They can be used in variable assignments, together with the Boolean operators.

**&&**

**||**

**!**

Examples:

$Boolean1=true;$Boolean2=false;$Boolean3=$Boolean1&&$Boolean2;

This will result in $Boolean3 being **false**.

$Boolean1=false;$Boolean2=!$boolean1;

This will result in $Boolean2 being **true**.

If Boolean values are used together with numbers, the following rules apply:

A value 0 or lower will be equal to Boolean false.

Any number above zero will be equal to Boolean true.

This may seem confusing if you come from C and expect negative numbers to also
be **true** but **Sputnik** is a higher level language
and as usual it considers numbers that are negative to be **false**
(as they are not above 0).

Example:

$Number1=0;$Boolean1=true;$Boolean2=$Number1&&$Boolean1;

This will result in $Boolean2 being false.

If you use arithmetics together with Boolean values (which is not advisable!), the following rules apply:

A Boolean **true** will be converted into the numeric value **1**.

A Boolean **false** will be converted into the numeric value **0**.

Example:

$Boolean1=true;$Number1=100;$Number2=$Boolean1+$Number1;

This will result in $Number2 to be the numeric value 101.

If you use strings together with Boolean values, they will be converted as follows:

A Boolean **true** will be the string value "**True**"
(case-insensitive) .

A Boolean **false** will be the string value "**False**"
(case-insensitive).

Example:

$Boolean1=true;$String1="Test is: ";$String2=$String1.$Boolean1;

This will result in $String2 being the string value "Test is: True"

The other way around however is different. When you use string comparisons
with Boolean values, the following rules apply:

Only an empty string ("") will be a Boolean false.

Any other string values (including a string equal "0") will be a Boolean
true.

Here is a rundown on how && and || operators work in **Sputnik**
internally.

The && operator works like so

$this && $that -- means If $this is true, return $that, else return
$this.

The || operator works like so

$this || $that -- means If $this is true, return $this, else return $that.

Contact

Cheryl (uberfox@hotmail.com)

Homepage

http://ubersoft.org