Booleans represent one of two values: true or false.
In programming you often need to know if an expression is true or false.
You can evaluate any expression in ChardScript, and get one of two answers, 1 or 0, 1 is true and 0 is false.
When you compare two values, the expression is evaluated and ChardScript returns the Boolean answer:
echo(10 > 9)
echo(10 == 9)
echo(10 < 9)
When you run a condition in an if statement, ChardScript returns true or false:
Print a message based on whether the condition is true or false:
call a = 200
call b = 33
if b > a then
echo("b is greater than a")
else
echo("b is not greater than a")
end
Functions can Return a Boolean
You can create functions that returns a Boolean Value:
Print the answer of a function:
You can execute code based on the Boolean answer of a function:
Print "YES!" if the function returns true, otherwise print "NO!":
ChardScript also has many built-in functions that return a boolean value, likeisnumber(), isstring(),islist()andisgroup()functions.
Check if an object is an number or not:
Check if an object is an string or not:
Check if an object is an list or not:
Check if an object is an function or not: