Difference between revisions of "false and true"

From Lazarus wiki
Jump to navigationJump to search
(internal link)
(review; add some example code)
Line 1: Line 1:
 
{{False}}
 
{{False}}
  
The [[Const|const]]ant '''false''' is used to define the false condition in a [[Boolean|boolean]] variable, as opposed to its opposite, [[True|true]]. This is a [[Manifest constant|manifest constant]] which is defined as part of the [[Standard type|standard data types]] the compiler initially knows about.
+
The [[Constant|constant]] <syntaxhighlight lang="pascal" enclose="none">false</syntaxhighlight> is used to define the false condition of a [[Boolean|<syntaxhighlight lang="pascal" enclose="none">boolean</syntaxhighlight>]] variable, as opposed to its opposite, [[True|<syntaxhighlight lang="pascal" enclose="none">true</syntaxhighlight>]].
 +
This is a [[Manifest constant|manifest constant]] which is defined as part of the [[Standard type|standard data types]] the compiler initially knows about.
  
 
This constant value must be predefined by the compiler as there is no way to define it in terms of anything else.
 
This constant value must be predefined by the compiler as there is no way to define it in terms of anything else.
 +
 +
<syntaxhighlight lang="pascal">
 +
program falseDemo(input, output, stderr);
 +
 +
uses
 +
typInfo;
 +
 +
begin
 +
writeLn(false);                            // prints FALSE
 +
 +
// enumerative actions ------------------------------------------
 +
writeLn(ord(false));                      // prints 0
 +
writeLn(succ(false));                      // prints TRUE
 +
// next two statements generate out-of-range compile-time warnings
 +
writeLn(pred(false));                      // prints TRUE
 +
writeLn(succ(succ(false)));                // prints TRUE
 +
 +
// data type ----------------------------------------------------
 +
writeLn(sizeOf(false));                    // prints 1
 +
writeLn(bitSizeOf(false));                // prints 8
 +
writeLn(PTypeInfo(typeInfo(false))^.kind); // prints tkBool
 +
writeLn(PTypeInfo(typeInfo(false))^.name); // prints Boolean
 +
end.
 +
</syntaxhighlight>

Revision as of 11:11, 2 May 2018

English (en)

The constant false is used to define the false condition of a boolean variable, as opposed to its opposite, true. This is a manifest constant which is defined as part of the standard data types the compiler initially knows about.

This constant value must be predefined by the compiler as there is no way to define it in terms of anything else.

program falseDemo(input, output, stderr);

uses
	typInfo;

begin
	writeLn(false);                            // prints FALSE
	
	// enumerative actions ------------------------------------------
	writeLn(ord(false));                       // prints 0
	writeLn(succ(false));                      // prints TRUE
	// next two statements generate out-of-range compile-time warnings
	writeLn(pred(false));                      // prints TRUE
	writeLn(succ(succ(false)));                // prints TRUE
	
	// data type ----------------------------------------------------
	writeLn(sizeOf(false));                    // prints 1
	writeLn(bitSizeOf(false));                 // prints 8
	writeLn(PTypeInfo(typeInfo(false))^.kind); // prints tkBool
	writeLn(PTypeInfo(typeInfo(false))^.name); // prints Boolean
end.