4 ms·
Another good real-world one that I've done is something like: for (bit = 1; bit <= 128; bit <<= 1) Personally, I like the flexibility.
by a_e_k 3y ago
Another good real-world one that I've done is something like:
for (bit = 1; bit <= 128; bit <<= 1)
Personally, I like the flexibility.
- bxparks 3y agoHeh, hopefully not too often. First I thought this loops 128 times. Then 7 times. Then 8 times. Then I thought "undefined behavior" if bit is a uint8_t. But then I thought, I don't have freaking clue because I can't keep all of C's implicit casting and arithmetic operation rules in my head.
- adrian_b 3y agoA better syntax for loops with geometric progressions like this would be obtained by modifying the syntax for writing arithmetic progressions (e.g. "a:b:c") by using a different separator symbol. For example, if the separator for geometric progressions would be ":>", your loop example would become "for bit in 1:>128:>2". Another example of (non-ASCII) separator would be "for bit in 1⋮128⋮2"
- kazinator 3y agoSuch syntax benefits from a comprehensive target language to compile into, in terms of which it can be understood, if necessary.