Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Conditional scan, using if
Message
From
15/02/2014 06:07:28
 
 
To
15/02/2014 05:47:00
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Environment versions
Visual FoxPro:
VFP 9 SP2
OS:
Windows Server 2012
Network:
Windows 2008 Server
Database:
MS SQL Server
Application:
Web
Miscellaneous
Thread ID:
01594372
Message ID:
01594382
Views:
49
It depends if "variable1" is a memory variable, and if it is static throughout the duration of the SCAN loop. If variable1 ever changes, your logic below will not be the same as the original posters. Your two programs would have different results.

With all things being equal, and if variable1 does not change, your version is probably slightly faster (marginally) because it's doing less testing for iteration. But beyond that there are disadvantages to the coding model you use, namely that it introduces double work to accomplish the same output, which introduces the opportunity for subtle errors to creep in on each edit.

Consider:

Suppose you need to make a change in your program. You have the top SCAN loop and you change some test from "x <= 4" to"x <= 5". On the bottom you go to make the same change, but accidentally type "x <= 6" and you don't catch it. In your initial testing you had never setup or anticipated having any "x = 6" conditions, so the logic appears to work properly even though the two are different. Later on when you expand your program and now have a valid x = 6 value, it begins to error out. Errors like that can creep in.

In general, it's just not good programming practice to duplicate your code as you have done when you can simply add a single test at the top and have it only scan through those items which are necessary. In terms of raw speed, your way is probably slightly faster.


>Sir, Scanning like the code you have suggested and the code I gave below makes the difference in Speed or performance.
>
>
>Select mytable
>if empty (variable1)
>scan for field2 = variable2
>Endscan
>Else
>scan for field1 = variable1
>Endscan
>Endif
>
>
>I am asking this just for my knowledge, if yes I will also make changes in my all of codes accordingly.
>Regards
>
>>
select mytable
>>
>>scan for iif(empty(variable1), field2 = variable2, field1 = variable1)
>>    * Code here
>>endscan
>>
Previous
Reply
Map
View

Click here to load this message in the networking platform