Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
DO CASE vs IF
Message
De
27/12/2000 20:09:41
Cindy Winegarden
Duke University Medical Center
Durham, Caroline du Nord, États-Unis
 
 
À
27/12/2000 19:56:18
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00457199
Message ID:
00457202
Vues:
21
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
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform