|
-
September 16th, 2009, 04:41 PM
#5
Re: ordering of IF-statement conditions
You can assume that the compiler will evaluate the conditions from left to right.
When coding i find myself doing something like this all the time. For example.
Code:
if(obj != null && obj.Value == 0)
If it didn't always check left to right and obj was null then it would throw an exception. However the compiler evaluates these conditions from left to right and as soon as a condition fails it stops and moves on.
If obj was null here in my example, it would never check obj.Value == 0 because it knows that no matter what the rest of the conditions are it cannot be true.
In your situation if delayInSecs == 0 it would never check --delayInSecs == 0 because the first statement satisfied the if condition it has no need to check the second one thus delayInSecs stays at 0 and will not become negative.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|