Avoid IF statement after condition has been met

Posted by greye on Stack Overflow See other posts from Stack Overflow or by greye
Published on 2010-03-26T06:54:05Z Indexed on 2010/03/26 7:03 UTC
Read the original article Hit count: 277

Filed under:
|
|

I have a division operation inside a cycle that repeats many times. It so happens that in the first few passes through the loop (more or less first 10 loops) the divisor is zero. Once it gains value, a div by zero error is not longer possible.

I have an if condition to test the divisor value in order to avoid the div by zero, but I am wondering that there is a performance impact that evaluating this if will have for each run in subsequent loops, especially since I know it's of no use anymore.

How should this be coded? in Python?

© Stack Overflow or respective owner

Related posts about if-condition

Related posts about python