Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
IIF vs. IF
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Title:
Miscellaneous
Thread ID:
00673310
Message ID:
00673323
Views:
15
Mike,
Since you basically don't want to do anything if switch = .F., then I would recommend using the if statement. VFP will assign a variable to itself each time. So in addition to the same check being done, you then have the added overhead of VFP having to read the value of the variable, do all that it needs to do to make sure the value will fit in the variable and then copy the value in to the memory space. While VERY FAST, it still takes time.

In my tests, you really didn't see any perceptible different until you reached 50000 iterations. SO if you really are doing 1,000,000,000,000 times, definitely use the IF.

Also, as a note, just use
if switch
instead of if switch == .T.. Since Switch is already a logical, you don't need the extra step.

HTH.

>I was wondering, in terms of 1)Speed and 2)Good Form...which is preferable.
>
>lntemp = iif(switch==.t., lntemp+1, lntemp)
>
>OR
>
>if switch == .t.
> lntemp = lntemp + 1
>endif
>
>
>Obviously, its nice to have just one line, thus the appeal of the iif. But it seem redundant to continually assign lntemp to itself, especially if the majority of the time 'switch ==.f.' Or is the compiler smart enough not to reassign a variable to itself?
>
>For Example:
>lntemp = 1
>* a trillion lines of...
>lntemp = lntemp
>
>i mean, assuming it takes only 1ns to assign a variable, that's either 1ns or ~17minutes
Larry Miller
MCSD
LWMiller3@verizon.net

Accumulate learning by study, understand what you learn by questioning. -- Mingjiao
Previous
Reply
Map
View

Click here to load this message in the networking platform