Questions tagged [loops]

For questions about the design or implementation of loops (e.g., for, while, do/while) in a programming language, including syntax and functionality.

Filter by
Sorted by
Tagged with
2 votes
0 answers
298 views

Pros and cons of treating endless loops as "anything can happen" UB, versus allowing limited reordering

Many programming languages, including C89, specify that the behavior of a program in terms of sequentially executed steps, whose behavior is in turn defined in terms of the program's state when the ...
supercat's user avatar
  • 1,714
9 votes
1 answer
394 views

Parsing `do`-`while`, `while`-`do`-`end` and `do`-`end`

Consider the Lua programming language, which has the following constructs involving the keywords do and end: ...
Luatic's user avatar
  • 298
5 votes
1 answer
205 views

Built-In Asynchronous Loops (Not Functions) - Do they / could they exist?

When writing a game's event loop, I always rely on a function from an external library, like draw() in ProcessingJS for ...
Quack E. Duck's user avatar
-4 votes
1 answer
230 views

What are the disadvantages of including foreach loops? [duplicate]

Yes, FOR loops. Those great things. There are good for shortening code. But there may be downsides I'm not aware of. I'm referring to Python style FOR loops. So, what are the disadvantages of ...
Starship - On Strike's user avatar
31 votes
16 answers
5k views

How could a language make the loop-and-a-half less error-prone?

Anyone who's used C-family languages enough will have seen or used a "loop-and-a-half", which can be written in one of two ways: ...
Bbrk24's user avatar
  • 8,857
9 votes
5 answers
368 views

What would a for loop return in an expression oriented language?

An expression-oriented language sounds appealing, as I could have code logic inline in expressions and initializers. An if statement could just return the last ...
user16217248's user avatar
  • 7,535
12 votes
3 answers
2k views

Why does Rust have an infinite loop construct?

The Rust programming language has an infinite loop construct, which looks like this: loop { <some code> } It's the only language I can think of that has ...
Ginger's user avatar
  • 2,579
7 votes
2 answers
166 views

What are the different options for breaking out of an inner loop?

In languages such as C, to break/continue out of an inner loop, there is no direct way so one must use ...
user16217248's user avatar
  • 7,535
5 votes
2 answers
221 views

How do I Interpret a Continue/Break Statement in a Loop?

Say I have the following construct in an interpreted language that uses an AST tree walker: ...
lyxal's user avatar
  • 1,775