Unconditional loops are unconditionally awesome
brson.github.io
Unconditional loops are unconditionally awesome
1–10 of 13 posts
Re: Unconditional loops are unconditionally awesome
#2[deleted]
Re: Unconditional loops are unconditionally awesome
#3While JS doesn’t have native support I do this with while (true) and a break clause. It’s very useful at times.
Re: Unconditional loops are unconditionally awesome
#4It has its uses but it's pretty low hanging fruit. I also think having the termination conditions in the loop header is much more readable most of the time
Re: Unconditional loops are unconditionally awesome
#5I 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's named let (or a decorator to enforce LLVMs "sibling recursion").
Re: Unconditional loops are unconditionally awesome
#6Couldn'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?
That'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.
Re: Unconditional loops are unconditionally awesome
#7If you are using C and want the same form of "satisfaction" then just do #define loop while(1)
Re: Unconditional loops are unconditionally awesome
#8Drop the condition and now you have unconditional loop: for(;;){}
Re: Unconditional loops are unconditionally awesome
#9If you are using C and want the same form of "satisfaction" then just do #define loop while(1)
#define ever ;;
for(ever){}
Re: Unconditional loops are unconditionally awesome
#10The problem is we don'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's famous goto fail; SSL bug? Sometimes it's not so easy to eyeball the code and follow the execution flow.
Specifying the condition for the loop up front makes me feel more confident about the loop safely concluding once the work is done.