'Nested if statements in cobol
I am trying to use nested if statements in Cobol. As far as I can tell I am following the style guides, but keep receiving the error:
file_name.cob:64: Error: syntax error, unexpected ELSE
^^ (This is the second ELSE statement)
The purpose of the code is to function as a Caesar cipher, but it seems to only be the nested if
statements that are producing the error. I tried putting the nested statements after the ELSE
clause of the initial IF
statement, but that was unsuccessful as well.
edit: I am using open-cobol, and and compiling with the -free
option
IF CharCount < 26
ADD firstnum, CharCount GIVING stringShift.
DISPLAY stringShift.
IF FUNCTION MOD(stringShift, 26) IS NOT ZERO
MOVE FUNCTION MOD(stringShift, 26) to stringShift
DISPLAY stringShift
MOVE abc(stringShift:stringShift) TO newChar
DISPLAY newChar
STRING newString DELIMITED BY "", newChar DELIMITED BY SIZE INTO newString
DISPLAY newString
ELSE
STRING newString DELIMITED BY "", searchChar DELIMITED BY SIZE INTO newString
DISPLAY newString
END-IF
ELSE
STRING newString DELIMITED BY "", searchChar DELIMITED BY SIZE INTO newString
DISPLAY newString
END-IF.
Thanks!
Solution 1:[1]
Just wanted to share the answer here, as it was answered in the comp.lang.cobol google group. It was the two periods after the first ADD and DISPLAY lines that were causing the problems. It now compiles successfully.
The lines should appear as:
ADD firstnum, CharCount GIVING stringShift
DISPLAY stringShift
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | argonXM |