Control Flow
In computer science, control flow (or flow of control) is the order in which individual statements, instructions or function calls of an imperative program are executed or evaluated. [1]
This page provides syntax for some of the common control flow methods in Julia . Each section includes an example to demonstrate the described methods.
Use Cases and Syntax
Test if a specified expression is true or false
Short-circuit evaluation
Test if all of the conditions are true
x && yTest if any of the conditions are true
x || yTest if a condition is not true
!z
Conditional evaluation
ifstatementif-elseif-elseif-else?:(ternary operator)
Conditional Statements
Input:
Output:
Loops
Repeat a block of code a specified number of times or until some condition is met.
whileloopforloopUse
breakto terminate loop
Input:
Output:
Comparison Operators and Functions
Equality
x == y or isequal(x, y)
Inequality
x != y or !isequal (x, y)
Less than
x < y
Less than or equal to
x <= y
Greater than
x > y
Greater than or equal to
x >= y
Input:
Output:
References
Wikipedia contributors. (n.d.). Control flow. In Wikipedia. Retrieved May 1, 2024, from https://en.wikipedia.org/wiki/Control_flow
Resources
Julia Documentation: Manual - Control Flow
Think Julia: Chapter 5 - Conditionals and Recursion
Think Julia: Chapter 7 - Iteration
Last updated
