Jump to content

Boolean values: Difference between revisions

no edit summary
m (→‎{{header|BASIC}}: fix markup)
No edit summary
Line 1,110:
 
Futhark has a <code>bool</code> type, with the two values <code>True</code> and <code>False</code>. They are used for branching.
 
 
=={{header|FutureBasic}}==
FB recognizes two types for boolean truth values: BOOL and boolean. There is a subtle difference between the two. A BOOL will accept without complaint two values, the macros YES, and NO, or the equivalent native FB constants, _true, and _false. However, although a BOOL can be assigned other values, it will throw a clang (FB"s native compiler) warning as with this example:
<syntaxhighlight lang="futurebasic">
window 1
BOOL boolTest
boolTest = -1
print boolTest
HandleEvents
</syntaxhighlight>
When compiled this code generates this warning:
<syntaxhighlight lang="futurebasic">
implicit conversion from constant value -1 to 'BOOL'; the only well defined values for 'BOOL' are YES and NO [-Wobjc-bool-constant-conversion]
</syntaxhighlight>
On the other hand, a Boolean can be assigned not only YES, NO, _true, or _false, but also any integer value, such as the common -1, an compile without complaint.
 
Since FB can also work with objects, native BOOLs and booleans need to be converted to objects as demonstrated in the code below.
 
Trivia: Because NULL and _nil zero values in FB, they evaluate to "NO" or “_false” in conditional expressions.
<syntaxhighlight lang="futurebasic">
void local fn BooleanExercise
BOOL areEqual = (1 == 1) // areEqual is YES
BOOL areNotEqual = not areEqual /* areNotEqual is converted to: areEqual = (-(1 == 1)). -1 throws a clang warning.
NOTE: FB does not accept the "!" shorthand for "not", i.e. !areEqual, common in other languages. */
print "areEqual == "; areEqual
print "areNotEqual == "; areNotEqual
print
// Boolean types assigned values outside YES or NO compile without complaint.
boolean minusOneTest = -1
print "minusOneTest == "; minusOneTest
// Typical boolean value is use
BOOL flatterRosettaReader = YES
if (flatterRosettaReader)
print
print @"Rosetta Code programmers understand booleans."
print
end if
// Defined Core Foundation boolean values
print "kCFBooleanTrue == "; kCFBooleanTrue
print "kCFBooleanFalse == "; kCFBooleanFalse
print
// Number object assigned literal value
CFNumberRef booleanObject = @(YES)
print "booleanObject == "; booleanObject
print
// Number object created programmatically
booleanObject = NO
print "booleanObject variable reassigned as N0 == "; fn NumberWithBool( booleanObject )
print
end fn
 
window 1
 
fn BooleanExercise
 
HandleEvents
</syntaxhighlight>
{{output}}
<pre>
areEqual == 1
areNotEqual == 0
 
minusOneTest == -1
 
Rosetta Code programmers understand booleans.
 
kCFBooleanTrue == 1
kCFBooleanFalse == 0
 
booleanObject == 1
 
booleanObject variable reassigned as N0 == 0
</pre>
 
 
 
=={{header|Gambas}}==
'''[https://gambas-playground.proko.eu/?gist=65324112fde86d51937b9cfcca0c51f9 Click this link to run this code]'''
729

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.