Boolean values: Difference between revisions

m
→‎{{header|COBOL}}: Added output tag, removed comments on syntax in code and formatted COBOL words.
(Added COBOL section explaining 'named-conditions')
m (→‎{{header|COBOL}}: Added output tag, removed comments on syntax in code and formatted COBOL words.)
Line 215:
Prior to COBOL 2002, there was no boolean data type, only ''condition names'' which could be used in conditional expressions. Condition names are subordinate to another data item, have the level-number 88, and are defined with the value(s) which their parent data item must have for them to be set to true. They can be defined like so:
<lang cobol> 01 X PIC 9.
* *> VALUE maybe followed by IS, or be replaced by VALUES,
* *> optionally followed by ARE.
88 X-Is-One VALUE 1.
88 X-Is-Even VALUE 0 2 4 6 8.
* *> THROUGH maybe used instead of THRU.
88 X-Larger-Than-5 VALUE 6 THRU 9.</lang>
 
Conditions can be <code>SET</code> to <code>TRUE</code> or <code>FALSE</code>. Setting a condition to <code>TRUE</code> will move the (first) value in the <code>VALUE</code> clause to the parent data item. In COBOL 2002, an optional <code>FALSE</code> clause was added which allowed the condition to be <code>SET</code> to <code>FALSE</code> and consequently set the parent data item to the specified value in the clause. A <code>FALSE</code> clause can only have one value. An example of conditions in action:
<lang cobol> PROGRAM-ID. Condition-Example.
 
Line 229 ⟶ 226:
01 Foo PIC 9 VALUE 5.
88 Is-Not-Zero VALUE 1 THRU 9
* *> FALSE is the only required word in this clause.
WHEN SET TO FALSE IS 0.
 
Line 253 ⟶ 249:
.</lang>
 
{{out}}
Output:
<pre>
Foo is not zero, it is 5.
Anonymous user