while(true) versus for(;;) [duplicate]
With optimizations enabled, they will compile identically. You should use whichever one you find more readable.
With optimizations enabled, they will compile identically. You should use whichever one you find more readable.
It is well defined behavior. In C11 a new clause 6.8.5 ad 6 has been added An iteration statement whose controlling expression is not a constant expression,156) that performs no input/output operations, does not access volatile objects, and performs no synchronization or atomic operations in its body, controlling expression, or (in the case of a … Read more
List<T>.GetEnumerator() returns a mutable value type (List<T>.Enumerator). You’re storing that value in the anonymous type. Now, let’s have a look at what this does: while (x.TempList.MoveNext()) { // Ignore this } That’s equivalent to: while (true) { var tmp = x.TempList; var result = tmp.MoveNext(); if (!result) { break; } // Original loop body } … Read more
byte is a 1-byte type so can vary between -128…127, so condition i < 128 is always true. When you add 1 to 127 it overflows and becomes -128 and so on in a (infinite) loop…
You can use the second argument of iter(), to call a function repeatedly until its return value matches that argument. This would loop forever as 1 will never be equal to 0 (which is the return value of int()): for _ in iter(int, 1): pass If you wanted an infinite loop using numbers that are … Read more
I’ll open by stating that this is one way to manage a long running process (LRP) — not de facto by any stretch. In my experience, the best possible product comes from concentrating on the specific problem you’re dealing with, while delegating supporting tech to other libraries. In this case, I’m referring to the act … Read more
C11 clarifies the answer to this question, in the draft C11 standard section 6.8.5 Iteration statements added the following paragraph: An iteration statement whose controlling expression is not a constant expression,156) that performs no input/output operations, does not access volatile objects, and performs no synchronization or atomic operations in its body, controlling expression, or (in … Read more
It’s not wrong per standard, it’s just a bad design. Constructors don’t usually block. Their purpose is to take a raw chunk of memory, and transform it into a valid C++ object. Destructors do the opposite: they take valid C++ objects and turn them back into raw chunks of memory. If your constructor blocks forever … Read more
If you want to study termination properties in depth, programs using successor-arithmetics are an ideal study object: You know a priori what they should describe, so you can concentrate on the more technical details. You will need to understand several notions. Universal termination The easiest way to explain it, is to consider Goal, false. This … Read more