Reputation: 31
This is what the code looks like:
******************************************************************
* Author:
* Date: 7/26/2022
* Purpose: Learning
* Tectonics: cobc
******************************************************************
IDENTIFICATION DIVISION.
PROGRAM-ID. LEARNING-COBOL.
AUTHOR. Olivier.
DATE-WRITTEN. July 26th 2022.
ENVIRONMENT DIVISION.
CONFIGURATION SECTION.
DATA DIVISION.
FILE SECTION.
WORKING-STORAGE SECTION.
01 Turn PIC 9 VALUE 1.
88 1turn VALUE 1.
88 4turn VALUE 4.
01 GameState PIC 9.
88 GameOver Value 1.
01 GameMove PIC 9.
LINKAGE SECTION.
PROCEDURE DIVISION.
PERFORM UNTIL GameOver
IF 1TURN THEN
DISPLAY "1 To Play"
ELSE IF 4turn THEN
DISPLAY "4 To Play"
END-IF
ACCEPT GameMove
MOVE 4 TO Turn
MOVE 1 TO GameState
END-PERFORM
STOP RUN.
END PROGRAM LEARNING-COBOL.
I do have so coding experience in other languages and I really feel like this should work, but I have absolutely no clue why. I have also tried removing the IF 4turn THEN and only leaving the ELSE and it does work. But why? I think i should exit the loop after waiting for an input, but it just is an infinite loop and doesnt wait for the input (ACCEPT).
Upvotes: 0
Views: 153
Reputation: 4407
You have two IF
statements, but only one END-IF
. Add a second END-IF
immediately following the current END-IF
.
That will terminate the the two IF
statements so that the code following the END-IF
s will execute.
As @Bruce Martin mentioned in a comment, GameState
should be given a value, such as, VALUE 0
. Without the VALUE
clause the condition GameOver
could be true
or false
depending on the default value provided by the compiler.
Upvotes: 3