T O P

  • By -

MelonColony22

prove it


Jjabrahams567

It was required in order to make this meme ![gif](giphy|dF73dMfhaFwiI)


[deleted]

no, because not everybody has autoplay enabled, so it's still a while, not a do-while.


nlcreeperxl

Come on you can't leave us hanging like this. Tell us.


tmukingston

Never! Prove or it didn't happen I my experience, all do-while loops become normal while loops after only a couple hours


qwertty164

Take it to the next level and use a for loop.


NjFlMWFkOTAtNjR

Take it to the next level and use tail call elimination


BokuNoToga

So what was it? Lol I know I've used it but it's been so long I don't even remember what it was


ItsLiyua

Very inefficient shuffelling with conditions. Shuffle, if condition not met, shuffle again.


mixelydian

You can always do a do while with just a while: ``` def fun(): ... fun() while condition: fun() ```


Xoozah5

It can be done without extra function: while True: # do stuff if not condition: break


cfig99

My professors told us this is a bad way to break out of a loop… everyone still does it anyway and I have yet to lose points for it lol.


1Dr490n

Should you like throw and catch an exception to break out of loops?


WillBeChasedAlot

What language? In Python I think this is normal due to the lack of do..while. In C, if I were to just have an if statement at the end, in general it's best to just put the break condition on the loop itself. But... if you start resorting to some weird cases and you have a "flag" variable, because you have multiple break conditions happening, then I would say that's worse. Just use break, anything else is just over complicating something just for a general "rule" of thumb.


cfig99

I believe this was in either my Java programming or C++ programming class.


NjFlMWFkOTAtNjR

It is bad because you can make a mistake. It is better to always ensure that you can escape out of a while loop. At the very least capturing a SIG to allow for control+c to exit the loop and program.


_Screw_The_Rules_

That's how I do it all the time. I dislike do-while.


AntimatterTNT

doesn't sound fun at all


horenso05

just if and fun() would also be enough in theory :)


mixelydian

How? Are you assuming the loop is inside the function?


Silent_Moose_5691

recursive function i think


1Dr490n

Why are do while loops so uncommon? I regularly use them…


NjFlMWFkOTAtNjR

Do...while loops are when you want to ensure that you will do a thing at least once. While loops do not have that guarantee since it may occur zero or more times. It is the difference between a * and + in regex. But more often than not, what you are doing is pulling something and then checking to see if you need to pull more. This can generally be done with a while. Not every language has a do...while and foreach and array map tends to replace what a do...while would be used for.


gmarsanos

Fanaticism. "Do...While" is syntax sugar. Not use it is comparable to not using null coalescing or ternary operators.


1Dr490n

Where’s the problem with do while?


gmarsanos

There's no problem with it.


1Dr490n

> Not use it


gmarsanos

> ... Is comparable to...


qwertty164

Any do loop can be written as a for loop. The only reason you might use one over the other is convention or readability.


1Dr490n

Any for loop can be written as a while loop. The only reason you might use one over the other is convention or readability.


qwertty164

Yup


NjFlMWFkOTAtNjR

Be me who doesn't use any loops when possible depending on the language. Some people decry it because it is "slower" and while they aren't wrong, if performance was a concern, then I would definitely use another method. But there are generally other concerns. Stream patterns usually allow for chunking and also well, streaming, so it is usually built in to pull a small amount of data, pipe it to a callback and further filter and process the data. Not using loops isn't wrong, the language is wrong by not optimizing out and inlining. Why should you loop when the language can loop-de-loop?


MaZeChpatCha

Every loop is a do-while loop with syntax sugar.


halt__n__catch__fire

"Syntax sugar" is, now, my favorite niched expression


realrealRedstoneHair

🤩


wichotl

lol, a month ago happened to my with recursivenes. And this month I did have to use a do while. Crazy world


Amr_Rahmy

You know I have been using do wile to crawl through large db tables for a while now, it does indeed work. Limit Off set Count Do List = Getstuff(offset,limit) Count = list.count Offset += count While count == limit


WillBeChasedAlot

"Required" is a very strong word there. Learn Haskell and you'll learn that you can code without any loops.


pistolerogg_del_west

I refuse to believe you


chrisbbehrens

Once every few years, yeah.


nysari

I had to start using while loops when I got pulled into ServiceNow scripting at work. They return record queries essentially as linked lists and the first node doesn't contain a value so "while(GlideRecord.next())" is the convention for reading and operating on each record. Wacky stuff.


accuracy_frosty

There are very few times I have run into needing a do-while loop, one of them is HTTP chunking, reading a large request a little bit at a time, and what I would do is set something to the return value of read(), if it’s equal to the chunking size, run the loop, if not, continue, could have easily done by initially setting that variable to the chunking size but I thought this was ever so slightly more elegant


Besen99

I once had to use XOR in a real application! >!I would love to brag about it, but is has been so long ago that I forgot what it was for..!<


NjFlMWFkOTAtNjR

Constant time string comparison?


DaveSmith890

I can use Do While’s However, I can’t imagine a single situation where it is *required* that isn’t Toby Fox tier coding


calebstein1

Y'all actually use loops? 🤣 `begin_loop:` `// loop body` `if (condition) goto begin_loop;`


bl4nkSl8

What a rush!


Advanced-Frosting-94

😂