‎2007 May 23 8:18 AM
hi experts
can anyone let me know the diff if and case stmts.
i read that performance wise case is good but how.
regads
alson
‎2007 May 23 8:23 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.
****do rewards if usefull
Regards,
vijay
‎2007 May 23 8:20 AM
if u want check only the value of a variable many no. of times u can go for Case.
otherwise always if statement only
I think u will understand after reading the statement(that we cannot do anything else with case statement).
Reward points if useful
Regards
Sudheer
‎2007 May 23 8:20 AM
Hi
Both does the same thing and have same meaning
but instead of writing more number of IF's we use CASE..endcase.
Reward points if useful
Regards
Anji
‎2007 May 23 8:23 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.
****do rewards if usefull
Regards,
vijay
‎2007 May 23 8:23 AM
Hi,
Let me try and explain using an example...
<b>1) For IF statement...</b>
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.<b>But if you use CASE Statement</b>
CASE COLOR.
when 'BLUE'.
statements.
when 'BLACK'.
statements.so follows that CASE is easy to use and performance wise is also better.
<i>Do reward each useful answer..!</i>
Thanks,
Tatvagna.
‎2007 May 23 8:29 AM
Hi.
have a look at this senario.in this if a = 4.in case of IF it should take a decition for 4 times(check a = 1 or not,check a = 2 or not,check a = 3 or not,check a = 4 or not,).where as in case of CASE always it will take decition once(check the value of a and directly goes to when 4).
if a = 1.
.....
elseif a = 2.
.......
elseif a = 3.
.......
elseif a = 4.
.......
endif.
*************************
case a.
when 1.
........
when 2.
........
when 3.
........
when 4.
........
endcase.
<b>reward if helpful</b>
rgds,
bharat.
‎2007 May 23 8:36 AM
Both does the same thing.
For reading case statment looks good.
Regards,
SaiRam
‎2007 May 23 8:40 AM
hi,
for if statement when it has no .of . conditions then control validates each n every condition n excutes the result.
in case of case a particular block is executed insted of executing each n every condition n control comes out of block.
so execution time for case is less when compared to if.s
if helpful reward some points.
with regards,
suresh babu aluri.
‎2007 May 23 8:41 AM
hey Alson,
Both these are used for checking multiple conditions like:
if (cond1
or cond2
and cond3...
...so on...)
<your logic>
where as case x:
when 'y'.
code...1
when 'z'.
code..2.
endcase.
for case, the system compares 'x' with the values followed by when and executes the logic followed by the matching when stmt.
of course by seeing it, it is clear that if is a bit lengthy and takes more time than case stmt.
Regards
Praveen
‎2007 May 23 9:33 AM
Hi alson
Yes you are right performance wise CASE is best,because CASE statement is useful when we are having multiple options for the same variable but when we have to use mutiple conditions simultaneously then it would be better to use if else.
1)CASE XXX.
when 'XXX1'.
Stmts.
endloop.
2)If XXX.
then stmts.
endif.
REWARD IF USEFUL......!!!