ACC97: Do...Loop That Uses Negative Logic Reverses Behavior of AND and OR Operators (236370)
The information in this article applies to:
This article was previously published under Q236370 Advanced: Requires expert coding, interoperability, and multiuser skills.
SYMPTOMS
When you use a Do...Loop that contains negative logic in the criteria of either the loop or in any logical test within the loop, the logical operators AND and OR reverse their behavior. For example, if you were to use either of the following code structures
Do While MyVar1 <> Val1 And MyVar2 <> Val2
' Perform some action.
Loop
Do Until rs.EOF
If MyVal1 <> Val1 And MyVal2 <> Val2 Then
' Perform some action.
End If
rs.MoveNext
Loop
the loop would end when either condition is true, rather than when both are true. If you were to use the OR operator instead of AND in the preceding code structures, the loop would not end until both conditions were true.
RESOLUTION
Use positive logic in the criteria line. For example, instead of using logic such as
Do While MyVar1 <> Val1 And MyVar2 <> Val2
' Perform some action.
Loop
use logic such as:
Do Until MyVar1 = Val1 And MyVar2 = Val2
' Perform some action.
Loop
Modification Type: | Major | Last Reviewed: | 9/26/2003 |
---|
Keywords: | kbprb KB236370 |
---|
|