0

In R, the following script results in a strange but annoying "error":

delta_t <- 0.0001
t <- 0
maxtime <- 2

repeat{
  t <- t + delta_t
  print(t)     
  if(t==maxtime){
    break
  }
}

All the printed values actually show that the time is incremented by delta_t:

0
0.0001
0.0002
.
.
.
2

However, if you stop the run before the time reaches the maxtime, and you check your workspace for te value of t, you'll see something like this: t = 1.852200000000159

This also causes R not to break out of the repeat loop. I know that it is possible to replace the argument that is used in the if loop by: t>=maxtime

But I have a code where I really need an equal to in stead of a greater than. Hope somebody can clarify this for me! Thanks in advance, Robin

Robin Trietsch
  • 1,662
  • 2
  • 19
  • 31

0 Answers0