Datatype boolThis is the easiest type. A boolean expresses a truth value. It can be either TRUE or FALSE. SyntaxTo specify a boolean literal, use either the keyword TRUE or FALSE. Both are case-insensitive. bFlag = true; // assign the value TRUE to bFlag Usually you use some kind of operator which returns a boolean value, and then pass it on to a control structure.
// == is an operator which returns a boolean
if (action == 1)
{
z=sqrt(z*sin(c));
}
// this is not necessary:
if (bFlag == TRUE)
{
return(sin(z));
}
// because you can simply type this:
if (bFlag)
{
return(sin(z));
}
Converting to/from booleanBoolean values are automatically converted to another datatype. Internally a boolean is simply an integer: So you can do calculations with booleans: real b; complex c; bool bFlag; bFlag=true; c=(1,2); b=c*bFlag; // bFlag will be converted to 1, so (1,2)*1=(1,2), converting to real results in 1 bFlag=false; b=c*bFlag; // bFlag will be converted to 0, so (1,2)*0=(0,0), converting to real results in 0 ChaosPro not only converts boolean values to other datatypes, but also it converts other datatypes to booleans if needed. The basic idea is:
if (d)
{
z=4;
}
Now when will d be true and when will d be false? The following table lists all possible datatypes for a variable named d and explains when the if condition
evaluates to true and thus z will be 4:
|
||||||||||||||||||||||||||||