Questions tagged [control-flow]

For questions about various ways or constructs to control the flow of a program, such as if statements, goto statements, loops, switch statements, etc.

Filter by
Sorted by
Tagged with
8 votes
1 answer

How can I account for expressions when building control-flow graphs?

How do statically typed programming languages build CFGs for programs containing expression-level control flow (e.g. ternary expressions, match expressions) which require transformation or extra ...
WZoG's user avatar
  • 83
31 votes
10 answers

Avoiding student confusion about the meaning of `x == a or b`

I'm designing a language intended to teach kids and other beginners how to program. It's just a fork of Python with a few extra features to make it easier to learn. I've noticed students make one ...
mousetail's user avatar
  • 8,111
12 votes
7 answers

A conditional block with unconditional intermediate code

One problem that is hard to make not at least somewhat repetitive is if there is code that needs to be executed in a certain order, and the intermediate code is unconditional but first and last code ...
user16217248's user avatar
  • 7,535
4 votes
1 answer

Correct terminology and relationship between program counters, continuations & contexts

Starting with a representation of a item of computation as an object which includes a method says how to perform the next step of its computation. ...
Bruce Adams's user avatar
  • 2,793
24 votes
3 answers

How to transpile goto to a language that lacks it?

I'm writing a transpile for a C-like language to Javascript, which lacks a goto statement. Unfortunately the existing library code contains a lot of ...
mousetail's user avatar
  • 8,111
10 votes
4 answers

How to transpile labelled break/continue statements to a high-level language which lacks them?

Suppose I am writing a source-to-source compiler (also called a transpiler) from one high-level imperative language to another, where the source language allows labelled statements to be targeted by <...
kaya3's user avatar
  • 17.3k
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
10 votes
1 answer

How do I implement AOT compilation of my 2-D esolang?

Background Trilangle is an interpreted 2-D esolang that I made in February and March of this year. At some point, I had the idea to implement an ahead-of-time compiler for the language, and what ...
Bbrk24's user avatar
  • 8,857
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
14 votes
13 answers

What are the pros and cons of goto?

Goto is often "considered harmful". But are there good reasons to have goto? If not, what are some of the cons associated with it that imply it should be avoided?
a coder's user avatar
  • 685
3 votes
3 answers

Why do some languages not have an 'unreachable' function?

Several languages have a function or macro to indicate that a certain point in control flow cannot be reached, even though the compiler cannot statically prove it, such as ...
Bbrk24's user avatar
  • 8,857
11 votes
2 answers

How do linear types interact with features that may change the normal control flow?

Linear types are quite a powerful feature of type systems that ensure that "linear values" are used exactly once. For example, ...
Luiz Felipe's user avatar
9 votes
3 answers

How to compile exceptions?

What are the most common ways of compiling code of a language with first-class support for exceptions, such as C++? Panics in Rust, which have similar behavior, shouldn't be too different. From my ...
Luiz Felipe's user avatar
6 votes
2 answers

What are the advantages of conditional statements having their own scope?

What are the advantages of conditionals having their own scope? I know this can lead to some extra variables for some programs. But it can also be more memory efficient. Credit to Hg0428 for the idea ...
Ethan's user avatar
  • 377
17 votes
7 answers

What are the pros and cons of having do ... while loops?

One somewhat rarely used, but still occasionally handy, feature of many programming languages is do ... while loops: ...
Rydwolf Programs's user avatar