Sorry for the stupid question. I was explaining some programming to my 13 years old daughter and got stuck while doing a simple exercise, focused on looping and logics. The idea was to create an "animated" point that bounces between 0 and 10 using the following code
a <- 0
for(i in 1:10000){
if(a == 10){
b <-1
}
if(a == 0){
b <- 0
}
if(b == 0){
a <- a + 0.1
}
if(b == 1){
a <- a - 0.1
}
plot(a, ylim = c(0,10))
}
That is, I would expect that when "a" becomes zero, "b" becomes 0 too and the script uses the additive formula (and the point moves upward), while when "a" equals 10, "b" becomes 1 and activates the subtractive formula (and the point moves downward). However, apparently the "if" command never catches that "a" equals 10 at some point. I've been trying to understand what's wrong with this. Any idea?