Reputation: 91
I'm new to COBOL and want to write a nested if statement. I'm getting errors on the ELSE-IF and ELSE. I'm sure it's a simple fix, but I can't figure out where I'm going wrong.
reading-procedure.
display "Enter Type of Pet: " with no advancing.
accept pet.
display "Enter Appointment Fee: " with no advancing.
accept fee.
IF pet = 'dog'
add fee total giving dogTotal.
add 1 to dogCount.
ELSE-IF pet = 'cat'
add fee total giving catTotal.
add 1 to catCount.
ELSE
add fee total giving otherTotal.
add 1 to otherCount.
END-IF
Upvotes: 2
Views: 14632
Reputation: 7287
There is no (standard) else-if
statement in COBOL.
In most cases where you have multiple branches EVALUATE TRUE
with WHEN condition-1 <statements> WHEN condition-2 <statements> [...] END-EVALUATE
is what you want to use - and in cases like your sample you can do EVALUATE pet WHEN 'dog' ... WHEN 'cat' ... END-EVALUATE
.
The reason why you are getting syntax errors for ELSE
is simple: you end them with your periods - get rid of them (the only part where you need them within PROCEDURE DIVISION
is before and after a paragraph/section/entry definition.
Upvotes: 9