Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
DO CASE vs IF
Message
From
27/12/2000 20:25:30
 
 
To
27/12/2000 20:09:41
Cindy Winegarden
Duke University Medical Center
Durham, North Carolina, United States
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00457199
Message ID:
00457205
Views:
18
Cindy:

Thanks for your reply :o)

I did create a test, and still trying diffrent methods. So far, I've found that the IF's return a little faster. Is this a fact or is it just the way I'm setting up my code? Do you see a problem in using a whole bunch of IF/ENDIF's in place of a DO CASE?

TIA

Mal


>Mal,
>
>>Feeling that IF's are faster than DO CASES, thought I'd ask.
>
>Don't just "feel" - if it's important, test. Make a program with a jillion loops and put your IF or your CASE code in the middle and run it.
>
>>
>>Besides code readability, do you see any problems by replacing DO CASE with IF's.?
>>
>>DO CASE
>>..CASE x="whatever1"
>>.....DO something
>>..CASE x="whatever2"
>>.....DO something
>>.....
>>..CASE x="whatever24"
>>.....DO something
>>ENDCASE
>>RETURN
>>
>>.OR.
>>
>>IF x="whatever1"
>>..DO something
>>..RETURN
>>ENDIF
>>
>>IF x="whatever2"
>>..DO something
>>..RETURN
>>ENDIF
>>
>>.......
>>
>>IF x="whatever24"
>>..DO something
>>..RETURN
>>ENDIF
>
>The problem with the code you have here is that CASE stops after the first true statement is encountered. Your IF code will do the first Something if it's true, and then go on to test for the second condition, and do the second Something also. To be equivalent to the CASE statement you would need to ELSE and nest the IFs inside that.
>IF
> * do something
>ELSE
> IF
> * do something
> ELSE
> IF ....
> ENDIF
>ENDIF
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform