Hi, I am a newbie in R Programming.
Studying for, while, and repeat loop coding.
for(i in 5:1) print(rep(i*2,i))
[1] 10 10 10 10 10
[1] 8 8 8 8
[1] 6 6 6
[1] 4 4
[1] 2
I completed for assignment however, I couldn't quite understand while and repeat function..
[while]
i<-10
while(i<=2){
+print(rep(i, i))
+i<-i-2
+}
[repeat]
i<-10
repeat{
-
if(i<2)break
-
print(rep(i,i))
-
i<-i-2
-
}
[1] 10 10 10 10 10 10 10 10 10 10
[1] 8 8 8 8 8 8 8 8
[1] 6 6 6 6 6 6
[1] 4 4 4 4
[1] 2 2
Can anyone see what is wrong with my code?
Thank you in advance!!