Foundation > Rogue Wave Script Language Reference > Booleans
 
Booleans
*Boolean Literal Syntax
*Automatic Conversion to a Boolean
*Boolean methods
*Logical Operators
Boolean Literal Syntax
There are two boolean literals: true, which represents the boolean value true, and false, which represents the boolean value false.
When converted to a number, true yields 1 and false yields 0.
Automatic Conversion to a Boolean
When a function, method or statement which expects a boolean as one of its arguments is passed a non-boolean value, this value is automatically converted to a boolean as follows:
*The number 0 yields false;
*The empty string "" yields false;
*The null value yields false;
*The undefined value yields false;
*Any other non-boolean values yield true.
For example:
if ("") writeln("True"); else writeln("False");
if (123) writeln("True"); else writeln("False");
displays "False", then "True".
Boolean methods
The only boolean method is:
Rogue Wave Script Boolean Method
Syntax
Effect
boolean.toString( )
Returns a string representing the boolean, either "true" or "false".
Example:
  true.toString −> "true"
  false.toString −> "false"
Logical Operators
The following boolean operators are available:
Note: For C/C++ programmers: These operators are the same as in C and C++.
Rogue Wave Script Logical Operators 
Syntax
Effect
! boolean
Logical negation.
Examples:
  ! true −> false
  ! false −> true
exp1 && exp2
Returns true if both boolean expressions exp1 and exp2 are true. Otherwise, returns false.
If exp1 is false, this expression immediately returns false without evaluating exp2, so any side effects of exp2 are not taken into account.
Examples:
  true && true −> true
  true && false −> false
  false && whatever −> false; whatever is not evaluated.
exp1 || exp2
Returns true if either boolean expression exp1 or exp2 is true. Otherwise, returns false.
If exp1 is true, this expression immediately returns true without evaluating exp2, so any side effects of exp2 are not taken into account.
Examples:
  false || true −> true
  false || false −> false
  true || whatever −> true; whatever is not evaluated.
condition ? exp1 : exp2
If condition is true, this expression returns exp1; otherwise, it returns exp2.
When condition is true, the expression exp2 is not evaluated, so any side effects it may contain are not taken into account. Similarly, when condition is false, exp1 is not evaluated.
Examples:
  true ? 3.14 : whatever −> 3.14
  false ? whatever : "Hello" −> "Hello"

Version 6.2.1
Copyright © 2018, Rogue Wave Software, Inc. All Rights Reserved.