DO Numeric [= Expression] to Expression [by Expression]
The iterator, Numeric, is set to the value of the Expression when present. The assignment is performed even if the loop block does not get executed. The expression on the To clause is the maximum possible value of the iterator. It is first checked to see if any loops are to be executed and exits the loop if not.
The expression in the optional By clause gives the value by which the iterator is incremented or, when negative, decremented. If no By clause is coded, the increment is one. After executing each loop the bound is checked to see if another loop can be run. Foir integers the checks are performed using signed arithmetic. If so the iterator will be incremented or decremented depending on the By clause and the next loop is run. After the last loop the iterator will have the value used in the last iteration.
The iterator must be a Local scalar numeric variable whose type is a Word, Cell, Single, or Double. If not previously declared the iterator is implicitly declared as a Word. The type of the iterator applies to the expressions on the Do command. The iterator may not be modified in the body of the loop.
Real numeric iterators have rounding and performance concerns. When working with values where arithmetic errors matter, consider using an integer iterator instead. If that is not possible, rounding effects should be carefully analysed. In most cases the method shown below is used to compute the number of iterations takes care of rounding problems???
Fudge = 0 IF abs( rem( End - Start, Increment )) <= abs( Increment / 2 ) Fudge = Increment / 2 . Count = floor[( End - Start + Fudge) / Increment ]
The count for real numbers is computed once before any loops are executed, even for constant bounds. This ensures the computations are performed using target machine instructions rather than the machine on which it is compiled. As IEEE-754 floating point numbers are now ubiquitous, these computations give the same results across popular architectures.
The value of the iterator is accumulated each iteration which may lead to an accumulation of rounding errors. The potential error after N loops is N times the potential amount of error in each addition.
Programmers need to consider rounding issues when performing any floating point operations. If in the context of a program you know the increment evenly divides the difference of the upper and lower bounds, then you should add half the increment to the end bound.
From = K; K is an integer value. End = From + .5 * K Step = .0001 DO V = From to End + Step / 2 by Step