fori loops code example
Example 1: r loops
# Basic syntax of for loop:
for (i in sequence) {
code to be repeated
}
# Example usage of for loop:
for (i in 1:5) {
print(i)
}
# Basic syntax of while loop:
while (condition_is_true) {
code to be repeated
}
# Example usage of while loop:
i = 1
while (i < 5) { # True while i is less than 5
print(i)
i = i + 1 # Increment i each iteration
}
Example 2: for loop
for(int i = 0; i < some_number; i++){
//inside loop do whatever you want
}