this post was submitted on 16 Jul 2023
1661 points (96.5% liked)

Memes

45726 readers
779 users here now

Rules:

  1. Be civil and nice.
  2. Try not to excessively repost, as a rule of thumb, wait at least 2 months to do it if you have to.

founded 5 years ago
MODERATORS
 
you are viewing a single comment's thread
view the rest of the comments
[โ€“] [email protected] -3 points 1 year ago* (last edited 1 year ago) (4 children)

I disagree. It's a while loop, because a for-loop is finite, so you can't count to infinity with it.

[โ€“] isildun 4 points 1 year ago

There's nothing special about a generic for loop (at least in C-like languages). There's no reason you couldn't do something like for (i = 0; true; i++) to make it infinite. Some languages even support an infinite list generator syntax like for i in [0..] (e.g. it lazily generates 0, then 1, then 2, etc. on each iteration) so you can use a for-each style loop to iterate infinitely.

Now, whether or not you should do such things is another question entirely. I won't pretend there aren't any instances where it's useful, but most of the time you're better off with a different structure.

load more comments (3 replies)