Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
To iif or not to iif = .t.
Message
General information
Forum:
Visual FoxPro
Category:
Coding, syntax & commands
Miscellaneous
Thread ID:
00513276
Message ID:
00514537
Views:
16
>>>> Thanks a lot for the suggestions, George. I already changed for next to do while and get rid of the top loop (unnecessary, as you fairy noted - this that I've done without reading this message). Now I'm going to proceed with your suggestions.
>>>>
>>>>Thanks.
>>>
>>>Nadya,
>>>
>>>You're welcome. Let me emphaize one thing. These are general guidelines. For example, my point about the inner of the two loops was based on the concept that, under the circumstances, this routine would only apply to tables connected with a DBC. My thought was, "Well, what about free tables? Why write essentially the same code twice to handle the,?" You know the answers to these questions far better than I.
>>>
>>>The rules are there for a purpose. Sometimes you have to break them in order to accomplish what needs to be done. However, before doing so, I try to make absolutely certain that the conditions of the problem require it, and there isn't a better way to accomplish the same thing.
>>
>>George,
>>
>>I changed the code (see bellow), but something bothers me. It seems that do while conditions are checked only when I rich the last enddo command. In other words,
>>
>>do while !Stop
>>  if Somecondition
>>      Stop=.t. && instead of immediate termination, this would terminate only after enddo
>>  endif
>>edndo
>>
>> May be it's only impression, but why I had to use do while lnK>>instead of do while m.lnK<=m.lnCount? If I put <=, I get an error.
>
>Is lnk being initialized? If it's only declared, then the default value is .F. In general this sort of situation is handled in the following:
* lnlast is the maximum number of iterations
>lni = 0
>llStop = lSomeCondition
>DO WHILE lni   lni = lni + 1
>  * Code here
>  llStop = lSomeCondition
>ENDDO
This pre-test structure will not execute if lnlast equals zero or llStop is initially set to .T. It will terminate, if executed if lni equals lnlast or if at some point llStop equals .T.

George,

This is a simple test, which confirms this undesired behavior of do while.
My desire: exit loop immediatelly after while condition evaluates to false. Do while behavior - checks condition only at the last enddo (e.g. finish one loop cycle, then check the condition):
lnK=0
lnCount=5
do while m.lnK&lt;=m.lnCount
   lnK=m.lnK+1
   ? lnK
   ? "In lnK=6 this line should never be executed!" 
enddo
If it's not broken, fix it until it is.


My Blog
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform