7 ms·
A for loop has a conditional in it. Unless by conditionals we mean “no if/else” and not “no branch instructions”.
by kiratp 10mo ago
A for loop has a conditional in it.
Unless by conditionals we mean “no if/else” and not “no branch instructions”.
- WhyNotHugo 10mo agoThe conditional here only makes it stop when it reaches 100. The solution can be adapted to use a while loop if you’re okay with it running indefinitely.
- kiratp 10mo agoA loop either never halts or has a conditional. I guess a compiler could elide a “while True:” to a branch-less jump instruction. One hack would be to use recursion and let stack exhaustion stop you.
- buzer 10mo agoOther would be to use goto (though Python doesn't have it) & introduce something that will panic/throw exception, like creating variable with value 1/(max-i).
- pinusc 10mo agoRecursion would work for that, you don't need goto. The division by zero trick is pretty good too!
- nodja 10mo agoCount down i from 100 to 0 and do 1/i at the end of the loop :)
- deleted 10mo ago[deleted]
- TZubiri 10mo agoYou could allocate 100 bytes and get a segfault on 101