In this particular example? It makes no sense to use continue at all.
As you mentioned, both code examples give exactly the same results. And not one of them will detect faster than the other.
The decision that you make, prefer, should be based on readability and clarity , and not on an attempt to optimize. With this in mind, the second is much clearer. I seriously doubt the programming of chops from those who used the first in a real code base.
As a basic guide, never use if-else when a single if will be executed. In this case, you compare != , And then find the opposite value with the else expression, which is almost like saying !(!=) , Which produces double negation. It is very difficult to read or understand. In general, you should try to evaluate the positive conditions in the if rather than the negative ones to prevent this from happening.
And there is no reason to post additional questions similar to this. All answers will be the same. Ignore any possible difference in performance (if it even exists, which is unlikely, given the optimizing compiler), and focus on which version is best for you as the person who needs to read it. Please ignore anyone who advises you otherwise.
source share