Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Hate Nested IFs? Consider this...
Message
 
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9
OS:
Windows 2000 SP4
Database:
Visual FoxPro
Miscellaneous
Thread ID:
01086217
Message ID:
01086229
Views:
10
no nesting or NOTs needed
llSuccess = 1st_Logical_Test and 2nd_Logical_Test and 3rd_Logical_Test
which I think is much clearer code to indicate overall success is dependent on each individual test being .t.

>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
df (was a 10 time MVP)

df FoxPro website
FoxPro Wiki site online, editable knowledgebase
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform