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

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

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

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

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

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

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

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

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

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