Previous Topic Next topic Print topic


Choices - in COBOL and

Choices in Managed COBOL

*>COBOL has no exact equivalent syntax to x ? y : z
 
if age < 20
   move "What's up?" to greeting
else
   move "Hello" to greeting
end-if
  
if x not = 100 and y < 5
   multiply 5 by x
   multiply 2 by y
end-if
 
*> evaluate is preferred in COBOL rather than if/else if/else
evaluate x
  when > 5
    multiply y by x
  when 5
    add y to x
  when < 10
    subtract y from x
  when other
    divide y into x
end-evaluate
  
evaluate color   *> can be any type
   when "torquoise"
   when "red"
      add 1 to r
   when "blue"
      add 1 to b
   when "green"
      add 1 to g
   when other
      add 1 to other-color
end-evaluate  

Portions of these examples were produced by Dr. Frank McCown, Harding University Computer Science Dept, and are licensed under a Creative Commons License.

Previous Topic Next topic Print topic