Application Development Discussions
Join the discussions or start your own on all things application development, including tools and APIs, programming models, and keeping your skills sharp.
cancel
Showing results for 
Search instead for 
Did you mean: 

Diff b/n else and elseif

Former Member
0 Kudos

Please help me to find out what are the cases else and elseif are used

In a particular case

I used

If condition

if

if

else

endif

endif

else.

if

if

else

endif

endif.

Endif.

In this case its not entering else

but it is working fine if it is elseif condition

Thanks.

1 ACCEPTED SOLUTION

Former Member
0 Kudos

Here is the difference

<b>ELSEIF</b>

Within a processing block enclosed by " IF ... ENDIF ", this statement indicates the processing to be executed if the logical expressions specified by IF and the preceding ELSEIF s are false, but the logical expression in this ELSEIF processing block is true.

Between the IF and ENDIF statements, there may be any number of ELSEIF s. These may be followed, optionally, by an ELSE statement, but this is executed only if none of the logical expressions under IF or ELSEIF is true.

Example


DATA RESULT TYPE I.
...
IF RESULT < 0.
  WRITE / 'Result less than zero'.
ELSEIF RESULT = 0.
  WRITE / 'Result equal zero'.
ELSE.
  WRITE / 'Result greater than zero'.
ENDIF.

Depending on the value of RESULT , the three different texts are output.

Related IF ,

ELSE ,

CASE

3 REPLIES 3

Former Member
0 Kudos

When you multiple IFs and ELSEIFs better use CASE ENDCASE.

This will avoid confusion and gives more code readability.

CASE <var>

WHEN <VALUE1>

*----


WHEN <VALUE2>

*----


WHEN <VALUEN>

*----


OTHERS

*------

ENDCASE

Thanks,

SKJ

Former Member
0 Kudos

Hi in this case,

1. If condition "if success control goes to point 2, if cond fails control -> point 7

2. if "if success control goes to point 3, if cond fails control -> point 6

3. if "if success control goes inside n executes code control ->point 5

"if condition fails control -> point 4 n exe code and control goes->5

4. else " this else is for 3 if condition

5. endif " for 3

6. endif " for 2

7. else. " this else is for 1 if condition

8. if

9. if

10. else " this else is for 9 if condition

11. endif

12. endif. " this is for 8 if condition

13. Endif. "for 1 if condition

        • i think this will make things clear.

Now, the difference between else n elseif

e.g:

if x eq 'A'

else. " This else works for anything else except 'A'

endif.

********

if x eq 'A'

elseif x eq 'B'. " This else works for only 'B'

endif.

elseif condition is nothing but if condition, but preceeded by another if condition.

  • Hpe it wil help u

Thank's

Ajay

Former Member
0 Kudos

Here is the difference

<b>ELSEIF</b>

Within a processing block enclosed by " IF ... ENDIF ", this statement indicates the processing to be executed if the logical expressions specified by IF and the preceding ELSEIF s are false, but the logical expression in this ELSEIF processing block is true.

Between the IF and ENDIF statements, there may be any number of ELSEIF s. These may be followed, optionally, by an ELSE statement, but this is executed only if none of the logical expressions under IF or ELSEIF is true.

Example


DATA RESULT TYPE I.
...
IF RESULT < 0.
  WRITE / 'Result less than zero'.
ELSEIF RESULT = 0.
  WRITE / 'Result equal zero'.
ELSE.
  WRITE / 'Result greater than zero'.
ENDIF.

Depending on the value of RESULT , the three different texts are output.

Related IF ,

ELSE ,

CASE