Boolean Data

Whereas numeric and string data types can have a virtually unlimited number of different values, the boolean data type can have only two. They are the literals true and false. A Boolean value expresses the validity of a condition (tells whether the condition is true or false).

Using Boolean Values

You can use a literal Boolean value (true or false) as the condition statement in a control structure. For example, you can create a potentially infinite loop using true as the condition for the while statement.

var s1 : String = "Sam W.";
var s2 : String = "";
while (true) {
   if(s2.Length<s1.Length)
      s2 = s2 + "*";
   else
      break;
}
print(s1);   // Prints Sam W.
print(s2);   // Prints ******

Note that the condition for breaking out of an infinite loop can be moved to the loop control, making it an explicitly finite loop. However, some loops can be written much more simply using the infinite loop construction.

Using a Boolean literal in an if...else statement allows you to easily include a statement or choose between statements in your program. This technique is useful for developing programs. However, it is more efficient to include a statement directly (without an if statement) or use comments to prevent inclusion of a statement.

For more information, see JScript Conditional Structures.

See Also

Reference

true Literal

false Literal

boolean Data Type (Visual Studio - JScript)

Boolean Object

Concepts

JScript Expressions

Other Resources

Data in JScript

JScript Conditional Structures