Files
carbon-lang/docs/design/control_flow
b17e69aefd Design overview update part 1 (#1274)
Reorganizes the sections, and makes a pass filling in and updating the first sections including: types, functions, user-defined types. The following sections are left for part 2, including names, generics, and interop.

Also some smaller updates to, not revisiting the text: `pattern_matching.md`, `control_flow/return.md`, and `lexical_conventions/numeric_literals.md`

Co-authored-by: Geoff Romer <gromer@google.com>
Co-authored-by: Chandler Carruth <chandlerc@gmail.com>
2022-06-09 12:58:22 -07:00
..
2021-08-12 08:20:46 -07:00

Control flow

Overview

Blocks of statements are generally executed linearly. However, statements are the primary place where this flow of execution can be controlled.

Carbon's flow control statements are:

  • if and else provides conditional execution of statements.
  • Loops:
    • while executes the loop body for as long as the loop expression returns True.
    • for iterates over an object, such as elements in an array.
    • break exits loops.
    • continue goes to the next iteration of a loop.
  • return ends the flow of execution within a function, returning it to the caller.