r while loop code example
Example 1: r while loop
# Basic syntax:
while (condition_is_true) {
code to be repeated
}
# Example usage:
i = 1
while (i < 5) { # True while i is less than 5
print(i)
i = i + 1 # Increment i each iteration
}
# Returns:
[1] 1
[1] 2
[1] 3
[1] 4
Example 2: while in r
while (test_expression)
{
statement
}