Why is this loop changed?

In this situation changing while() to for() is not an optimization. There is simply no way to know from bytecode which one was used in a source code. There are many situations when: while(x) is the same as: for(;x;) Suppose we have a three similar java applications – one with while() statement, and two with …

Read more

Why only one warning in a loop?

It is by design. See the docs at https://docs.python.org/3/library/warnings.html: Repetitions of a particular warning for the same source location are typically suppressed. You can override this behavior by adding a filter with the keyword “always”, as in: import warnings warnings.simplefilter(‘always’, UserWarning) for i in range(10): print(i) warnings.warn(‘this is a warning message’)

Benefit of endless-loops without side effects in C++ being undefined behavior compared to C?

The reasons are optimizations only. If the compiler can assume that all loops without side effects terminate, it does not have to prove that. If the non-terminating loops were allowed, the compiler would be allowed to perform certain optimizations only if it could prove termination, that is impossible in general so it would turn into …

Read more