我只是Cobol编程的新手我必须挑战自己在循环中做一个练习循环。
我的输出是
JOHN.SMITH 5
5
4
3
2
1
**********
JOHN.SMITH 4
4
3
2
1
**********
.
.
.
JOHN.SMITH 1
1
**********
这是我的代码,我无法打印出来,因为我在想我的问题。谢谢
*-----------------------------
IDENTIFICATION DIVISION.
*-----------------------------
PROGRAM-ID. TESTLOOP1.
AUTHOR. JOHN.S
*-----------------------------
ENVIRONMENT DIVISION.
*-----------------------------
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-4381.
OBJECT-COMPUTER. IBM-4381.
SPECIAL-NAMES.
INPUT-OUTPUT SECTION.
*--------------------*
DATA DIVISION.
*--------------------*
*-----------------------*
*-----------------------*
WORKING-STORAGE SECTION.
*-----------------------*
01 WORK.
05 WS-NAME PIC X(7) VALUE 'JOHN'.
05 WS-PEJA PIC X(01) VALUE '.'.
05 WS-SURNAME PIC X(12) VALUE 'SMITH'.
05 WS-COUNT1 PIC 9(01) VALUE 5.
05 WS-COUNT2 PIC 9(01) VALUE 5.
05 WS-STAR PIC X(10) VALUE '**********'.
05 WS-FULLNAME PIC X(11) VALUE SPACE.
05 WS-COUNT3 PIC 9(01) VALUE 5.
*---------------------
PROCEDURE DIVISION.
*----------------------
MOVE WS-NAME TO WS-FULLNAME.
MOVE WS-PEJA TO WS-FULLNAME(8:1).
MOVE WS-SURNAME TO WS-FULLNAME(9:2).
A-PARA.
PERFORM B-PARA UNTIL WS-COUNT1 LESS THAN 1.
STOP RUN.
B-PARA.
DISPLAY WS-FULLNAME WS-COUNT1.
PERFORM C-PARA UNTIL WS-COUNT2 LESS THAN 1.
SUBTRACT 1 FROM WS-COUNT1.
DISPLAY '**********'.
PERFORM D-PARA.
C-PARA.
DISPLAY WS-COUNT2.
SUBTRACT 1 FROM WS-COUNT2.
D-PARA.
SUBTRACT 1 FROM WS-COUNT3.
*****************************************************************
答案 0 :(得分:0)
您的代码按照您在此处编写的方式工作。
您将
WS-COUNT1
,WS-COUNT2
,WS-COUNT3
设为5
A-PARA
中 您在B-PARA
上执行while循环,直到WS-COUNT1
小于1
。 停止程序
B-PARA
中 在WS-COUNT1
中显示全名和当前计数 您在C-PARA
上执行while循环,直到WS-COUNT2
小于1
。 使用WS-COUNT1
减少1
打印**********
执行D-PARA降低
C-PARA
中 在WS-COUNT2
中显示当前计数 使用WS-COUNT2
1
降低
D-PARA
中 使用WS-COUNT3
1
转换为javascript,你得到:
var fullname = "John .Sm";
var WSCOUNT1 = 5;
var WSCOUNT2 = 5;
var WSCOUNT3 = 5;
APARA();
function APARA() {
while(WSCOUNT1 > 0) {
BPARA();
}
}
function BPARA() {
console.log(fullname, WSCOUNT1);
while(WSCOUNT2 > 0) {
CPARA();
}
WSCOUNT1--;
console.log("**********");
DPARA();
}
function CPARA() {
console.log(WSCOUNT2);
WSCOUNT2--;
}
function DPARA() {
WSCOUNT3--;
}

你可能想要的是BPARA
每次迭代的1,2,3,4,5,其中包含由WS-COUNT3定义的1,2,3,4,5的项目数。
在每次迭代中,您的WS-COUNT2
和WS-COUNT3
都不会重置为原始值。
当你循环循环时,你必须记住"重置"你的价值观让你可以重新思考。
所以你的代码修正了(参见B-PARA段落中的*>
条评论):
查看实际操作:http://tpcg.io/41dqNT
IDENTIFICATION DIVISION.
PROGRAM-ID. TESTLOOP1.
AUTHOR. JOHN.S
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
SOURCE-COMPUTER. IBM-4381.
OBJECT-COMPUTER. IBM-4381.
SPECIAL-NAMES.
INPUT-OUTPUT SECTION.
DATA DIVISION.
WORKING-STORAGE SECTION.
01 WORK.
05 WS-NAME PIC X(7) VALUE 'JOHN'.
05 WS-PEJA PIC X(01) VALUE '.'.
05 WS-SURNAME PIC X(12) VALUE 'SMITH'.
05 WS-COUNT1 PIC 9(01) VALUE 5.
05 WS-COUNT2 PIC 9(01) VALUE 5.
05 WS-STAR PIC X(10) VALUE '**********'.
05 WS-FULLNAME PIC X(11) VALUE SPACE.
05 WS-COUNT3 PIC 9(01) VALUE 5.
PROCEDURE DIVISION.
MOVE WS-NAME TO WS-FULLNAME.
MOVE WS-PEJA TO WS-FULLNAME(8:1).
MOVE WS-SURNAME TO WS-FULLNAME(9:2).
A-PARA.
PERFORM B-PARA UNTIL WS-COUNT1 LESS THAN 1.
MOVE 5 to WS-COUNT3.
STOP RUN.
B-PARA.
*> SET WS-COUNT2 to WS-COUNT3 Value.
MOVE WS-COUNT3 to WS-COUNT2.
DISPLAY WS-FULLNAME WS-COUNT1.
PERFORM C-PARA UNTIL WS-COUNT2 LESS THAN 1.
SUBTRACT 1 FROM WS-COUNT1.
DISPLAY '**********'.
*> DECREASE WS-COUNT3
PERFORM D-PARA.
C-PARA.
DISPLAY WS-COUNT2.
SUBTRACT 1 FROM WS-COUNT2.
D-PARA.
SUBTRACT 1 FROM WS-COUNT3.
然后输出:
JOHN .SM 5
5
4
3
2
1
**********
JOHN .SM 4
4
3
2
1
**********
JOHN .SM 3
3
2
1
**********
JOHN .SM 2
2
1
**********
JOHN .SM 1
1
**********
- 免责声明,我之前从未编写过COBOL编码,可能有更好的方法。这是我自己在COBOL中的首次涉猎