TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Unconditional loops are unconditionally awesome

10 pointsby akbarnamaover 4 years ago

8 comments

h_anna_hover 4 years ago
If you are using C and want the same form of "satisfaction" then just do #define loop while(1)
评论 #25826831 未加载
sangliover 4 years ago
Couldn&#x27;t you do this in any language? Either write a do while or write a infinite loop with true as condition and then write breaks in the loop itself?<p>That&#x27;s what I mostly do in java, write a while(true) and then either come back to change the condition or write break in the loop.
dr_kiszonkaover 4 years ago
One thing I don&#x27;t know how to do in Python is using while loops to collect results of some other loop that runs at the same time.<p>For example, within the same script, I would have a simulate_magic_numbers function with a loop that produces a sequence of magic numbers continuously for a few hours and returns them once done. Below, I would like to have a while loop that grabs the magic numbers every 10 minutes and plots them.<p>I know how to do it with two separate scripts and saving intermediate numbers to a file, but it would be great to be able to do it within a single Jupiter notebook. However, there doesn&#x27;t seem to be a straight-forward way of doing it.
评论 #25882543 未加载
评论 #25829769 未加载
omarforgotpwdover 4 years ago
The problem is we don&#x27;t always write perfect code, so if you forget to return or break on any given branch (I.e. in some else statement) you could get stuck in the loop forever. Remember Apple&#x27;s famous goto fail; SSL bug? Sometimes it&#x27;s not so easy to eyeball the code and follow the execution flow.<p>Specifying the condition for the loop up front makes me feel more confident about the loop safely concluding once the work is done.
mhh__over 4 years ago
It has its uses but it&#x27;s pretty low hanging fruit. I also think having the termination conditions in the loop header is much more readable most of the time
bjoliover 4 years ago
I have written very little rust code, but loop is probably the thing I like the least. It requires mutation to be useful in most cases, even for things where you could avoid it. I would much rather have something like scheme&#x27;s named let (or a decorator to enforce LLVMs &quot;sibling recursion&quot;).
brockwhittakerover 4 years ago
While JS doesn’t have native support I do this with while (true) and a break clause. It’s very useful at times.
adembudakover 4 years ago
Drop the condition and now you have unconditional loop: for(;;){}