Hi,
I once had this message from Sapero about FOR-NEXT loops. I did try to work it out,
but I was defeated, as I am with most stuff from Sapero!
Anybody fancy a go?
There is an undocumented syntax for the for-next loop - it can accept any type of variables:
Code:
for (optional definition+optional assign, continue condition, increment or decrement)
for (float f=START; f<LAST; f+=STEP)
next f
Code:
for (double d=START; d>LAST; d-=STEP)
next d
Code:
for (; f>LAST; f-=STEP) ' optimized (f=f;
next f
Please don't post it on the forums, because LarryMC will shot 100 questions in my direction 
The "float f" part is allowed inside FOR header if the "f" variable isn't defined yet. If you prefer to define all variables first, use the following syntax:
Code:
float f
for (f=START; f<LAST; f+=STEP)
Where START, LAST and STEP are numbers - integers or floats.
Internally the FOR loop is converted to an WHILE loop. The variable passed to NEXT is required, but ignored. Anything you pass there should be accepted, even an undefined variable.
I've posted it here 'cos I know LarryMC can't shoot 100 questions in Sapero's direction!
Brian
			
			
			
				Oh Bri .. what on earth are you doing ? You'll give yourself headaches trying that .. :o
A FOR loop is intended to work with integers, but if you need steps of say 0.1, or 0.01 it's much easier than that ..
Trust a computer whizz to do it the complicated way ..  :)
Try this ..
openconsole
cls
' test of a decimal FOR loop .. multiply the controls by 10 for steps of 0.1
' by 100 for steps of 0.01 .. etc ..
def i,start,finish,inc:int
def step:float
' to run from 1.2 to 1.6 in increments of 0.1 ..
start = 12
finish = 16
inc = 1
for i = start to finish step inc
	print i/10
next i
do:until inkey$<>""
closeconsole
end
all the best, :)
Graham
			
			
			
				Graham,
You know, I can't even remember what my original question to Sapero was, and what program
I was attempting at the time! Although I don't remember asking how to do it in .1 increments
like you have just shown me, so that's another one for the memory banks...
Brian
			
			
			
				Quote from: Brian Pugh on January 25, 2013, 05:54:23 AM
Please don't post it on the forums, because LarryMC will shot 100 questions in my direction 
That was because I made him explain what he was doing so I could document it in the help file. ;D