Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
IIF vs. IF
Message
Information générale
Forum:
Visual FoxPro
Catégorie:
Codage, syntaxe et commandes
Titre:
Divers
Thread ID:
00673310
Message ID:
00673525
Vues:
15
Mike,

I would go for the IF construct as it is easier to read and understand and you will spend much more time maintaining the code than you will writing it. Also you can simplify your code by dropping the =.T. stuff, a logical value is a logical expression that is either .T. or .F. so IF Switch is the same as IF Switch = .T. Also the == in VFP is only for character strings so it is not needed with logical values. This makes you comparison become;
lnTemp = lnTemp + IIF(Switch,1,0)

versus

IF Switch
  lnTemp = lnTemp + 1
ENDIF
>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
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform