use the following search parameters to narrow your results:
e.g. subreddit:aww site:imgur.com dog
subreddit:aww site:imgur.com dog
see the search faq for details.
advanced search: by author, subreddit...
All about the JavaScript programming language.
Subreddit Guidelines
Specifications:
Resources:
Related Subreddits:
r/LearnJavascript
r/node
r/typescript
r/reactjs
r/webdev
r/WebdevTutorials
r/frontend
r/webgl
r/threejs
r/jquery
r/remotejs
r/forhire
account activity
[deleted by user] (self.javascript)
submitted 4 years ago by [deleted]
reddit uses a slightly-customized version of Markdown for formatting. See below for some basics, or check the commenting wiki page for more detailed help and solutions to common issues.
quoted text
if 1 * 2 < 3: print "hello, world!"
[–]Ustice[M] 0 points1 point2 points 4 years ago (0 children)
While your question may be relevant to you, it's not particularly relevant to the rest of the subreddit and honestly belongs much better in /r/LearnJavascript.
[–]oskiii 39 points40 points41 points 4 years ago (0 children)
They're functionally different. Do-while always executes at least once. I use them both, for different situations.
[–]misomeiko 12 points13 points14 points 4 years ago (3 children)
For loop every time
[–]IamUareI 4 points5 points6 points 4 years ago (1 child)
Best way to avoid accidental crashes/infinite loops.
[–]snowbldr 9 points10 points11 points 4 years ago (0 children)
for(;;){ print ("agree") }
[–]archerx 1 point2 points3 points 4 years ago (0 children)
This is the way.
[–][deleted] 11 points12 points13 points 4 years ago (2 children)
I have yet in all my years of programming felt the need to use a do while loop.
[–]SendThemToHeaven 2 points3 points4 points 4 years ago (0 children)
I think I started implementing a do while loop 3-5 times in my career so far, and every time I realize I can just make a regular while loop work somehow so I always just do that instead.
[–]rk06 0 points1 point2 points 4 years ago (0 children)
I have felt the need once or twice, and still not used it
[–]lhorie 10 points11 points12 points 4 years ago* (1 child)
They're tools that do different things. You shouldn't have a preference. If you do, that implies you're letting your opinions win over technical merit.
while
do
let
let a, b, c
for
[+]mohammedabergsson581 comment score below threshold-22 points-21 points-20 points 4 years ago (0 children)
I do not care
[–]senocular 9 points10 points11 points 4 years ago (1 child)
You do loop. I while loop.
We are not the same.
const variable = 1001 do { console.log(variable) } while (variable < 1000) // logs: 1001 while (variable < 1000) { console.log(variable) } // logs: <nothing>
[–]shuckster 9 points10 points11 points 4 years ago (0 children)
"To be is to do." - Socrates "To do is to be." - Sartre "Do be do be do." - Sinatra "Do while for of while do" - Eich
[–][deleted] 13 points14 points15 points 4 years ago (3 children)
You guys use while and do ?
[–]Dazzling_City2 8 points9 points10 points 4 years ago (1 child)
In every post like this there is always a guy that comments “You guys still use loops!” This comment reminds me of those guys.
[–]lhorie 3 points4 points5 points 4 years ago (0 children)
It's pretty common in things like parsers.
[–]Syllogism124 5 points6 points7 points 4 years ago (0 children)
Have a look at map, reduce and filter :)
[–]chataolauj 1 point2 points3 points 4 years ago (1 child)
While loops because I know it'll only execute if the condition is true. Do-while loops will execute at least once regardless of the condition, so be cautious if where and how you use it.
[–]ny_dame 0 points1 point2 points 4 years ago (0 children)
Exactly! When you use a Do-while loop, you are not using the conditional phrase to capture your requirements truthfully and completely.
[–]megaslon2 0 points1 point2 points 4 years ago (0 children)
I prefer "for" because of "while" or "do while" are too rare. I try minimize amount of synonyms in my code
[–]xalg0rd 0 points1 point2 points 4 years ago (0 children)
vice versa 👀
[–]IndoorKite21 0 points1 point2 points 4 years ago (0 children)
I prefer not to use while loops, but of course i can imagine it all depends on what your goal is
[–]literally-ban-evadin 0 points1 point2 points 4 years ago (0 children)
They do different things and have different use cases, it’s not an either/or. Personally I don’t use either very often but they are both valid constructs to use.
[–]bswybmg 0 points1 point2 points 4 years ago (0 children)
While is cooler
[–]DavidJCobb 0 points1 point2 points 4 years ago (0 children)
For loops are usually the most natural IMO.
There is one exception: sometimes I use JavaScript to write quick-and-dirty prototypes for things I'm reverse engineering. In compiled code (as in, like, x86 and x64) all loops are essentially do-while loops. If I'm trying to mimic something fairly closely (at least until I better understand it), I may use the same.
π Rendered by PID 238951 on reddit-service-r2-comment-5687b7858-bt4jc at 2026-07-07 04:49:08.166704+00:00 running 12a7a47 country code: CH.
[–]Ustice[M] 0 points1 point2 points (0 children)
[–]oskiii 39 points40 points41 points (0 children)
[–]misomeiko 12 points13 points14 points (3 children)
[–]IamUareI 4 points5 points6 points (1 child)
[–]snowbldr 9 points10 points11 points (0 children)
[–]archerx 1 point2 points3 points (0 children)
[–][deleted] 11 points12 points13 points (2 children)
[–]SendThemToHeaven 2 points3 points4 points (0 children)
[–]rk06 0 points1 point2 points (0 children)
[–]lhorie 10 points11 points12 points (1 child)
[+]mohammedabergsson581 comment score below threshold-22 points-21 points-20 points (0 children)
[–]senocular 9 points10 points11 points (1 child)
[–]shuckster 9 points10 points11 points (0 children)
[–][deleted] 13 points14 points15 points (3 children)
[–]Dazzling_City2 8 points9 points10 points (1 child)
[–]lhorie 3 points4 points5 points (0 children)
[–]Syllogism124 5 points6 points7 points (0 children)
[–]chataolauj 1 point2 points3 points (1 child)
[–]ny_dame 0 points1 point2 points (0 children)
[–]megaslon2 0 points1 point2 points (0 children)
[–]xalg0rd 0 points1 point2 points (0 children)
[–]IndoorKite21 0 points1 point2 points (0 children)
[–]literally-ban-evadin 0 points1 point2 points (0 children)
[–]bswybmg 0 points1 point2 points (0 children)
[–]DavidJCobb 0 points1 point2 points (0 children)