Skip to content

Instantly share code, notes, and snippets.

@DrNickRedfern
Last active September 8, 2022 10:19
Show Gist options
  • Save DrNickRedfern/19d563c05772c052f32ee204b976d9c7 to your computer and use it in GitHub Desktop.
Save DrNickRedfern/19d563c05772c052f32ee204b976d9c7 to your computer and use it in GitHub Desktop.
An illustration of a while loop in R
# 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