Glossary

Control flow

In programming, control flow refers to the order in which individual instructions, statements, or function calls are executed or evaluated in a script or program. It is essentially the roadmap that dictates how a program moves through different tasks, determining which actions are performed and when.

Control flow allows a program to make decisions, repeat tasks, and respond to various conditions dynamically.

At its core, there are three basic types of control flow:

  1. Sequential execution: This is the default mode, where the program executes statements one after the other, in the order they appear in the code.
  2. Conditional branching: Programs can make decisions based on conditions. For instance, with if-else statements, a program can choose to execute certain blocks of code only if specific conditions are met. If the condition is false, the program can take an alternative path.
  3. Loops: These allow a program to repeat certain actions multiple times. Loops like for or while are commonly used to iterate over data structures or execute a block of code until a particular condition is satisfied.

In Apple’s Shortcuts app, control flow is implemented through scripting actions that mirror the basic concepts used in programming. You can find these under the Action Panel in the Shortcut editor, under Scripting.

For example, users can create more dynamic automations by using Repeat or Repeat with Each actions to loop through items, and If actions to execute different sets of instructions based on a condition.

With these actions, you can make your shortcuts behave like small programs, making decisions and repeating tasks without having to manually intervene. This allows you to automate complex workflows with just a few control flow actions.

[glossary-list]