Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Hate Nested IFs? Consider this...
Message
 
 
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Versions des environnements
Visual FoxPro:
VFP 9
OS:
Windows 2000 SP4
Database:
Visual FoxPro
Divers
Thread ID:
01086217
Message ID:
01086266
Vues:
17
Mark,

You asked for this <g>

Please, re-write using DO CASE <g>
SELECT c_letter_series_masters

LOCATE FOR cDepartment_code = lcDepartment_code AND cClient_code = lcClient_hospital_id

IF FOUND()

      lcLetter_series_masters_pk = c_letter_series_masters.cLetter_series_masters_pk

      llFound = .T.

ELSE

      LOCATE FOR cDepartment_code = lcDepartment_code

      IF FOUND()

            lcLetter_series_masters_pk = c_letter_series_masters.cLetter_series_masters_pk

            llFound = .T.

      ELSE

            LOCATE FOR cClient_code = lcClient_hospital_id

            IF FOUND()

                  lcLetter_series_masters_pk = cLetter_series_masters_pk

                  llFound = .T.

            ENDIF

      ENDIF

ENDIF
>Jim,
>
>I took this from your comments in the GLGDW thread...
>
>>Some people hate (with a capital H) nesting of IFs simply because they can't stand the indenting. I don't worry about how much indenting is done.
>
>Here is a tip as an alternate to nested IFs that I use just because it is easier for ME to follow:
>
>local llSuccess
>llSuccess = .T.
>DO CASE
>   CASE NOT 1st_Logical_Test
>       llSuccess = .F.
>   CASE NOT 2nd_Logical_Test
>       llSuccess = .F.
>   CASE NOT 3rd_Logical_Test
>       llSuccess = .F.
>   OTHERWISE
>       llSuccess = .T.
>ENDCASE
>RETURN llSuccess
>Just remove the "llSuccess = .F." lines above or the "OTHERWISE" clause depending on your preference. That DO CASE is the same as --
>LOCAL llSuccess
>llSuccess = .F.
>IF 1st_Logical_Test
>   IF 2nd_Logical_Test
>      IF 3rd_Logical_Test
>         llSuccess = .T.
>      ENDIF
>   ENDIF
>ENDIF
>RETURN llSuccess
If it's not broken, fix it until it is.


My Blog
Précédent
Suivant
Répondre
Fil
Voir

Click here to load this message in the networking platform