Do all the things like ++ or -- rants, post your own rants, comment on others' rants and build your customized dev avatarSign Up
rookiemaverick5391126dGo-to is not wrong but your use case indeed
schil22736126dEncounterd this today, actually. Fixed it by using a boolean to keep track of the state and used it to break out of the loop.
Really though, having nested loops is a code smell, and usually means there's logic to be extracted. One nested is alright, any more is pushing it.
deadPix3l1374126d@schil227 semi agreed. But it really helps when dealing with multiple dimensional arrays.
Or the case I've seen the most. You are dealing with a two dimensional arrays in an infinite loop. That's a while true, and then two for loops for a depth of 3. Getting all the way out, and halting is just not pretty without goto.
I've admittedly done the Boolean tracking, but it just feels cleaner to define a label at the end of the nesting and just goto that.
vhoyer1538126dcan't you just encapsulate the loop in a function and return when you are done?
deadPix3l1374125d@vhoyer @schil227 I guess you could, but what if you need a clean up step like freeing some pointers or a final adjustment to the value or good forbid another loop for whatever reason!
My point is yea it's possible to avoid goto entirely and many people do, but I believe there are small niche cases where it is the only clean, acceptable answer.
Your Job Suck?
Take a quick quiz from Triplebyte to skip the job search hassles and jump to final interviews at hot tech firms
Get a Better Job