Control Flow
Use Cases & Syntax
Used to test if a specific case is true or false
Short-circuit evaluation:
Test if all conditions are true
Test if any conditions are true
Test if a condition is not true
Conditional evaluation
If statement: run code if this statement is true
Only used at the beginning of a conditional statement
Else if statement: if previous statements aren't true, try this
Can be used an unlimited number of times in an if statement
Else statement: catch-all for anything outside of prior statements
Only used to end a conditional statement
Inputs:
Outputs:
Loops
Repeats a block of code a specified number of times or until some condition is met
While loop
For loop
Use break to terminate loop
Inputs:
Outputs:
Comparison Operators
>
Greater than
<
Less than
>=
Greater than or equal
<=
Less than or equal
==
Exactly equal
!=
Not equal to
&
Entry wise and
Input:
Output:
Resources
R Documentation: Conditional Execution
R Documentation: Repetitive Execution
Last updated