Concept Flow - Assignment operators
Start
Evaluate Right Side
Assign Value to Left Variable
Variable Updated
End
The program evaluates the right side expression, then assigns the result to the variable on the left, updating its value.
x <- 5 x <- x + 3 x
| Step | Code Line | Variable | Value Before | Operation | Value After | Output |
|---|---|---|---|---|---|---|
| 1 | x <- 5 | x | undefined | Assign 5 | 5 | |
| 2 | x <- x + 3 | x | 5 | Add 3 and assign | 8 | |
| 3 | x | x | 8 | Output value | 8 | 8 |
| 4 | End | Execution stops |
| Variable | Start | After Step 1 | After Step 2 | After Step 3 |
|---|---|---|---|---|
| x | undefined | 5 | 8 | 8 |
Assignment operators in R: - Use '<-' to assign values: x <- 5 - To add and assign: x <- x + 3 - Variable must be defined before using it on right side - Right side evaluated first, then assigned - Updates variable value in place