FOR ... TO statement

Hi, is there a way to tell the FOR… TO statement to use an increment other than 1? Other languages can do that, but I can’t find the right trick in Navision. Anna

Replace the FOR / TO with a WHILE / DO. That should give you the degree of control you’re after.

Or you can just do the math your self. FOR i := 1 to EndVal do BEGIN j := i * 3; .. fucntion using j .... END; same as incrementing by 3.

That brings up an interesting point while programming in Navision. When programming in C or C++, the use of FOR statements is common, where Navision doesn’t use that much FOR statements. Whereas Navision uses more REPEAT UNTIL statements. Just babbling I guess…[:P]

quote:

Or you can just do the math your self. FOR i := 1 to EndVal do BEGIN j := i * 3; .. fucntion using j .... END; same as incrementing by 3.
Originally posted by David Singleton - 2006 Feb 03 : 13:13:56
Mhmm… yes, that should work. Of course, EndVal must be the actual end value DIV 3. Thank you for the tip [:)] Anna

Hope it helps. Dead Lizzard, the difference is that in most loop scenarious, the number of itterations will be a function of the number of records int he table, thus reapeat until makes sense. FOR…TO is only really when you have a fixed number of itterations. Code like MyRec.FIND('-'); FOR i := 1 to COUNT DO BEGIN ...code... myrec.next; END: is not common.

I do agree with David, the mentioned code would take longer to run as you have the additional COUNT statement to know upfront how many records you will have to read. the use of a foreach(element in elementlist) { some code } is basically also a REPEAT / UNTIL and not a FOR /NEXT. Of course I know that the “Length” in an Elementlist in other languages is at least sometimes a property, but in most cases it is a function.