Last active
September 8, 2022 10:19
-
-
Save DrNickRedfern/19d563c05772c052f32ee204b976d9c7 to your computer and use it in GitHub Desktop.
An illustration of a while loop in R
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Set the initial value of a | |
a <- 1 | |
# Print the current value of a while a is less than or equal to 5 | |
while (a <= 5){ | |
# Print the current value of a | |
print(a) | |
# Increment the value of a by 1 | |
a = a + 1 | |
} | |
[1] 1 | |
[1] 2 | |
[1] 3 | |
[1] 4 | |
[1] 5 | |
# Note that the final value of a when the loop exited is six | |
a | |
[1] 6 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment