Question Issue with While loop

digitaldrew

Well-known member
Joined
Nov 10, 2012
Messages
167
Programming Experience
Beginner
Hey everyone..Having a bit of an issue, but can't see where I'm going wrong here.

I'm making a call and putting the response in a string..the response will be something like "WORKING" so after I get the initial response, I want to loop through and do a check, so I can spot when that response changes to "COMPLETE"

VB.NET:
                        statusCheck = Statusresponse("step")  'Here I am setting the string

                        While statusCheck <> "COMPLETE" Or statusCheck <> "ERROR" Or statusCheck <> "CANCEL"
                            Thread.Sleep(500)
                            Statusresponse = status.OperationInfo(ApiKey, RegisterResponse("id")) 'Here I am re-checking the status
                            statusCheck = Statusresponse("step") 'Here I am saving the new response into the same string
                        End While

The problem with my code above is that even when statusCheck changes to COMPLETE..it still seams to be running through the loop.

Update: think I figured it out, need to use AND instead of OR
 
Last edited:
Update: think I figured it out, need to use AND instead of OR

Yes, that's right. This:
VB.NET:
statusCheck <> "COMPLETE" Or statusCheck <> "ERROR" Or statusCheck <> "CANCEL"
is always going to be true because `statusCheck` can only ever have one value at a time so it will always not be equal to at least two of the values you're comparing to and `True Or True Or False` is always going to be True.

That said, you should rarely actually be using And and Or at all anyway. You should almost universally be using AndAlso and OrElse. That means that, in this case, you should be using AndAlso.
 
Back
Top