R-loops: Repeat, While and For: Simple Code Examples

> i=20
> repeat {if (i > 100) break else {print(i); i = i + 5;}}
[1] 20
[1] 25
[1] 30
[1] 35
[1] 40
[1] 45
[1] 50
[1] 55
[1] 60
[1] 65
[1] 70
[1] 75
[1] 80
[1] 85
[1] 90
[1] 95
[1] 100
> i=5
> while(i<=25){print(i);i=i+5}
[1] 5
[1] 10
[1] 15
[1] 20
[1] 25
> for (i in seq(from=5,to=25,by=5)) print(i)
[1] 5
[1] 10
[1] 15
[1] 20
[1] 25

Leave a Comment

Your email address will not be published. Required fields are marked *