Use decimal number increment for the code DO LOOP

For questions that don't fall into one of the categories above, such as working with the RATS interface, using Wizards, etc.
Brc
Posts: 19
Joined: Thu Jun 20, 2024 5:16 pm

Use decimal number increment for the code DO LOOP

Unread post by Brc »

I need to use Do loop with increment 0.1

Let's say that the variable X is defined between 1 and 11 with increment 0.1.
DO X = 1,11,0.1

....

END DO X


When I run this code, RATS gives error on "usage of real integer number" as an increment.

How can I use a decimal number as an increment in DO LOOP?

Thank you for your helps.
TomDoan
Posts: 7814
Joined: Wed Nov 01, 2006 4:36 pm

Re: Use decimal number increment for the code DO LOOP

Unread post by TomDoan »

You can't use DO with non-integers. Use the more general DOFOR:

dofor [real] x = %SEQRANGE(1,11,101)
   ?x
end dofor

Note that you really can't just ask to go from 1 to 11 by steps of .1 with machine arithmetic (which is why %SEQRANGE uses a count rather than an increment). Because .1 isn't represented exactly in binary, adding .1 100 times might or might not end up hitting 11 exactly. It will round to 11, but might actually be something like 10.99999999999.
Post Reply