‎2007 Jul 04 6:28 AM
Hi all,
Plz let me know the difference between IF and CASE statements.Which one is better to be used in general...and are there any specific situations where we have to go for CASE insted of IF.
Rgds,
Reddy.
‎2007 Jul 04 6:31 AM
Hi,
Case statement we can use for different type of situation occurence instead of using or in if case but if statement we are using for one situatation check max.
Regards,
Nandha
reward if it helps
‎2007 Jul 04 6:31 AM
Hi
CASE is also a kind of IF...ELSE stmnt. (may be for 3 or 4)
For few conditions to check and act accordingly, we prefer IF...ELSE....
If the conditions are more ..then CASE stmnt is preferred..
CASE <field>
WHEN <value>
<code>
WHEN <value>
<code>
WHEN <value>
<code>
ENDCASE.
Regards
Raj
‎2007 Jul 04 6:32 AM
Hi
If it is 1 or 2 conditions use IF..ELSE..ENDIF.
if there are more conditions better to use CASE..WHEN..ENDCASE.
Reward points for useful Answers
Regards
Anji
‎2007 Jul 04 6:33 AM
Hi,
Case statement is good for performance wise because here we declare cases
and according to these cases program will be executed.
When we use if statement then the cursur goes to in the loop, when ever
the loop is not complete till then the programme will not execute.
Thats by in performance basis the case statement is good.
Let me try and explain using an example...
1) For IF statement...
Suppost you have a variable color..and you are checking it against color names.
then your code will be
IF COLOR == 'BLUE'.
statements
ELSEIF COLOR == 'BLACK'.
statements.
...and so on....
ENDIF.
But if you use CASE Statement
CASE COLOR.
when 'BLUE'.
statements.
when 'BLACK'.
statements.
so follows that CASE is easy to use and performance wise is also better.
Regards,
Priyanka.
‎2007 Jul 04 6:33 AM
Hi,
The behaviour is same, that is the effect that you want to have is same.
But If you have lot of alternatives cases it looks ODD when you put then in IF ELSEIF and ENDIF's. In such a case CASE ENDCASE is more useful interms of readability.
CASE is supposed to be faster compared to IF.
Regards,
Sesh
‎2007 Jul 04 6:34 AM
hi
u can use any of these
but if there are large number of conditons to check
then performance wise and also according to the scenario
we prefer to use CASE statement
regards
ravish
<b>plz dont forget to reward points if helpful</b>
‎2007 Jul 04 6:36 AM
Hello,
Choice is your requirement:
Using IF-ENDIF condition you can have any logical expression line EQ, NE, CP etc. Also NOT, OR , AND relational logic.
Howevere in CASE- ENDCASE you check for equality only.
Regards,
A.Singh
‎2007 Jul 04 6:36 AM
HI,
it is better to use case instead of using elseif(condition) block.
if u use elseif means to execute the code in elseif it should take decision twice(once at if(condition) and other at elseif(condition)).like this if u use 10 elseif (condition) statements in ur if...endif block to execute the 10 th block it should take the decision for 11 times.it will degarde the performance.in case of CASE it always will take decision once.so in these types of situations we have to use case.
<b>reward if helpful</b>
rgds,
bharat.