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:
00673342
Views:
16
Mike;

Seems like we went over this a few days ago - which is faster, If or IIF.

Here is another take on the issue if you are going to have a large number of records to process at a time. Which statement should come first? Now it may depend and if speed is an issue I would suggest understanding if false or true appear most often. If it is a toss up then it does not matter. So what I am suggesting is if say 20% of the time false is the answer use

If llTrue
* 80% true
else
* 20% false
Endif

This can really be a "mixed bag" depending upon many factors. Years ago I did everything to insure I processed records at the fastest speed possible. Unless it is a life and death issue I do not worry that much about such things any more.

I have tested If and IIF and have obtained mixed results. Most of the time I use If for readability. In reports IIF is great! IIF can be hard to read especially if you are using nested IIF's!

Just be thankful you are not using Visual Basic and have a speed issue while processing a large number of records! Visual Basic will evaluate both sides of an If statement and then give the answer - a three step process. I cannot say if VB.NET has improved this. :)

Tom

>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
Previous
Reply
Map
View

Click here to load this message in the networking platform