大多数编程语言将任何非零数字和非空字符串识别为true。我想知道COBOL是否也一样?
Example1:(9 && 2)被识别(true && true),因此返回trueExample2:(“” &&“ Hello”)被识别(false && true),因此返回false
谢谢!
通过Google搜索:
布尔数据项COBOL不直接支持逻辑/布尔变量但是,级别88用于定义条件名称,具有相同的效果。
大多数编程语言将任何非零数字和非空字符串识别为true。我想知道COBOL是否也一样?
没有这样的使用会导致语法错误。
procedure division.
if 9 and 2
display "true"
else
display "false"
end-if
if "" and "Hello"
display "true"
else
display "false"
end-if
stop run
.
1 procedure division.
2 if 9 and 2
* 315-S************ ( 0)**
** Invalid conditional expression
3 display "true"
4 else
* 562-S******** ( 1)**
** An "ELSE" phrase did not have a matching IF and was discarded.
5 display "false"
6 end-if
* 564-S********** ( 1)**
** A scope-delimiter did not have a matching verb and was discarded.
7 if "" and "Hello"
*1010-E********* ( 1)**
** Nonnumeric literal has length of zero. One SPACE assumed.
* 315-S************* ( 1)**
** Invalid conditional expression
8 display "true"
9 else
* 562-S******** ( 1)**
** An "ELSE" phrase did not have a matching IF and was discarded.
10 display "false"
11 end-if
* 564-S********** ( 1)**
** A scope-delimiter did not have a matching verb and was discarded.
12 stop run
13 .
Cobol 没有与其他语言一样具有布尔值,取而代之的是88个级别。88个级别可以应用于其他类型。它们涵盖布尔值和枚举其他语言。
您可以做
05 Filler pix x value 'N'.
88 end-of-file value 'Y'.
88 more-date-in-file value 'N'
perform until end-of-file
...
read Transaction-File
at end set end-of-file to True
end-perform
03 Transaction-Code pic s9(4) comp-3.
88 Purchase-Transaction value 1000, 1001, 1005 thru 1009.
88 Sales-Transaction value 2000, 2010, 2020.
88 Price-Adjustment value 2050.
88 Transfer-Transaction value 1050.
evaluate true
when Purchase-Transaction
...
when Sales-Transaction
...
88级提供基本的布尔变量(但不提供布尔代数)。他们也允许您记录变量可以采用的可能值+含义