Application Development and Automation 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: 
Read only

IF and case

Former Member
0 Likes
1,002

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

1 ACCEPTED SOLUTION
Read only

Former Member
0 Likes
965

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

9 REPLIES 9
Read only

Former Member
0 Likes
965

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

Read only

Former Member
0 Likes
965

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

Read only

Former Member
0 Likes
966

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

Read only

Former Member
0 Likes
965

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.

Read only

Former Member
0 Likes
965

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.

Read only

former_member196280
Active Contributor
0 Likes
965

Both does the same thing.

For reading case statment looks good.

Regards,

SaiRam

Read only

Former Member
0 Likes
965

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.

Read only

Former Member
0 Likes
965

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

Read only

Former Member
0 Likes
965

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......!!!