How to Write IF Conditions Correctly ( And Vs. Or)

In COBOL, IF condition is popular. Here is the best way to use ‘and’/ ‘or’ conditions. If you don’t give parenthesis correctly, the condition may not work as expected. Recently I have faced the same problem.

Here is My Best Suggestion How to Use conditions

IF abc > 'HI'
and mfg = '10' or '20' '20'
do-this
END-IF.

The above logic will not work correctly since its parenthesis not correct. When you would need to use ‘or’ follow the below way:

IF (abc > 'HI')
and (mfg = '10' or '20' '20')
do-this
END-IF.

The other way you can write as:

IF abc > 'HI'
and (mfg = '10' or '20' '20')
do-this
END-IF.

The other best example

IF (abc > 'HI')
or (mfg_unit = 'HYD')
do-this
END-IF.

Related posts

Author: Srini

Experienced software developer. Skills in Development, Coding, Testing and Debugging. Good Data analytic skills (Data Warehousing and BI). Also skills in Mainframe.