How can I make sense of the `else` clause of Python loops?

Many Python programmers are probably unaware that the syntax of while loops and for loops includes an optional else: clause: for val in iterable: do_something(val) else: clean_up() The body of the else clause is a good place for certain kinds of clean-up actions, and is executed on normal termination of the loop: I.e., exiting the … Read more

Java method with return type compiles without return statement

Question 1: Why does the following code compile without having a return statement? public int a() { while(true); } Notice: If I add return after the while then I get an Unreachable Code Error. Question 2: On the other hand, why does the following code compile, public int a() { while(0 == 0); } even … Read more

Are loops really faster in reverse?

I’ve heard this quite a few times. Are JavaScript loops really faster when counting backward? If so, why? I’ve seen a few test suite examples showing that reversed loops are quicker, but I can’t find any explanation as to why! I’m assuming it’s because the loop no longer has to evaluate a property each time … Read more

Are loops really faster in reverse?

I’ve heard this quite a few times. Are JavaScript loops really faster when counting backward? If so, why? I’ve seen a few test suite examples showing that reversed loops are quicker, but I can’t find any explanation as to why! I’m assuming it’s because the loop no longer has to evaluate a property each time … Read more