• Re: Nested If else statements

    From Tony Ennis@21:1/5 to Kerry Liles on Wed Nov 3 04:46:25 2021
    On Thursday, 25 April 2013 at 20:00:23 UTC+1, Kerry Liles wrote:
    On 4/25/2013 2:38 PM, kpie...@gmail.com wrote:
    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.

    I am using open-cobol, and and compiling with the '-free' option on the 1.1 compiler

    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.

    Note: I know this is a beginner question, but have looked at a lot of documentation and am at a loss.

    Thanks!

    Assuming you pasted the code verbatim in your example, the periods in
    the two statements immediately after "IF CharCount < 26" are part of the problem... If you are using END-IF scope delimiters, do NOT use periods
    at the end of any statement except the last statement in a paragraph!
    The period at the end of "ADD firstnum, CharCount GIVING stringShift." terminates the IF - not at all what you intended.

    HTH
    Thank you too sir. I had same issue, looking around for hours how to sort it out!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kerry Liles@21:1/5 to Tony Ennis on Wed Nov 3 10:36:31 2021
    On 11/3/2021 7:46 AM, Tony Ennis wrote:
    On Thursday, 25 April 2013 at 20:00:23 UTC+1, Kerry Liles wrote:
    On 4/25/2013 2:38 PM, kpie...@gmail.com wrote:
    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.

    I am using open-cobol, and and compiling with the '-free' option on the 1.1 compiler

    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.

    Note: I know this is a beginner question, but have looked at a lot of documentation and am at a loss.

    Thanks!

    Assuming you pasted the code verbatim in your example, the periods in
    the two statements immediately after "IF CharCount < 26" are part of the
    problem... If you are using END-IF scope delimiters, do NOT use periods
    at the end of any statement except the last statement in a paragraph!
    The period at the end of "ADD firstnum, CharCount GIVING stringShift."
    terminates the IF - not at all what you intended.

    HTH
    Thank you too sir. I had same issue, looking around for hours how to sort it out!



    Funny that this post showed up today... just last night I was thinking
    that COBOL should have an option to DISallow the use of periods thus
    making sure there is no chance of misinterpretation...

    This of course would mean getting rid of the diagnostic/error that
    occurs if there is no period on the statement BEFORE a paragraph start.

    THAT error always annoyed the hello out of me - if there is a NEW
    paragraph name why is there an error? The previous paragraph obviously
    has therefore ended. Same argument can be applied to having the useless
    period immediately AFTER the paragraph name!

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Robert Jones@21:1/5 to Kerry Liles on Wed Nov 3 11:43:31 2021
    On Wednesday, November 3, 2021 at 2:36:34 PM UTC, Kerry Liles wrote:
    On 11/3/2021 7:46 AM, Tony Ennis wrote:
    On Thursday, 25 April 2013 at 20:00:23 UTC+1, Kerry Liles wrote:
    On 4/25/2013 2:38 PM, kpie...@gmail.com wrote:
    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.

    I am using open-cobol, and and compiling with the '-free' option on the 1.1 compiler

    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.

    Note: I know this is a beginner question, but have looked at a lot of documentation and am at a loss.

    Thanks!

    Assuming you pasted the code verbatim in your example, the periods in
    the two statements immediately after "IF CharCount < 26" are part of the >> problem... If you are using END-IF scope delimiters, do NOT use periods >> at the end of any statement except the last statement in a paragraph!
    The period at the end of "ADD firstnum, CharCount GIVING stringShift."
    terminates the IF - not at all what you intended.

    HTH
    Thank you too sir. I had same issue, looking around for hours how to sort it out!

    Funny that this post showed up today... just last night I was thinking
    that COBOL should have an option to DISallow the use of periods thus
    making sure there is no chance of misinterpretation...

    This of course would mean getting rid of the diagnostic/error that
    occurs if there is no period on the statement BEFORE a paragraph start.

    THAT error always annoyed the hello out of me - if there is a NEW
    paragraph name why is there an error? The previous paragraph obviously
    has therefore ended. Same argument can be applied to having the useless period immediately AFTER the paragraph name!

    How would you expect a compiler to distinguish a paragraph name from an misspelt operand, e.g.
    DISPLAY data-name
    paragraph-name ADD something
    ?
    What I have started doing is putting the full stop before and after the paragraph name as follows
    DISPLAY data-name
    . paragraph-name. ADD something

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)
  • From Kerry Liles@21:1/5 to Robert Jones on Wed Nov 3 15:18:10 2021
    On 11/3/2021 2:43 PM, Robert Jones wrote:
    On Wednesday, November 3, 2021 at 2:36:34 PM UTC, Kerry Liles wrote:
    On 11/3/2021 7:46 AM, Tony Ennis wrote:
    On Thursday, 25 April 2013 at 20:00:23 UTC+1, Kerry Liles wrote:
    On 4/25/2013 2:38 PM, kpie...@gmail.com wrote:
    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.

    I am using open-cobol, and and compiling with the '-free' option on the 1.1 compiler

    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.

    Note: I know this is a beginner question, but have looked at a lot of documentation and am at a loss.

    Thanks!

    Assuming you pasted the code verbatim in your example, the periods in
    the two statements immediately after "IF CharCount < 26" are part of the >>>> problem... If you are using END-IF scope delimiters, do NOT use periods >>>> at the end of any statement except the last statement in a paragraph!
    The period at the end of "ADD firstnum, CharCount GIVING stringShift." >>>> terminates the IF - not at all what you intended.

    HTH
    Thank you too sir. I had same issue, looking around for hours how to sort it out!

    Funny that this post showed up today... just last night I was thinking
    that COBOL should have an option to DISallow the use of periods thus
    making sure there is no chance of misinterpretation...

    This of course would mean getting rid of the diagnostic/error that
    occurs if there is no period on the statement BEFORE a paragraph start.

    THAT error always annoyed the hello out of me - if there is a NEW
    paragraph name why is there an error? The previous paragraph obviously
    has therefore ended. Same argument can be applied to having the useless
    period immediately AFTER the paragraph name!

    How would you expect a compiler to distinguish a paragraph name from an misspelt operand, e.g.
    DISPLAY data-name
    paragraph-name ADD something
    ?
    What I have started doing is putting the full stop before and after the paragraph name as follows
    DISPLAY data-name
    . paragraph-name. ADD something


    ah, good point. I was thinking (only) about the sort of COBOL I have
    used the most over the last 50+ years - where Paragraph names have to
    start in the A margin (column 8). I often forget about the "looser"
    COBOL variants like those available on PCs etc.

    --- SoupGate-Win32 v1.05
    * Origin: fsxNet Usenet Gateway (21:1/5)