PureBasic Forum
https://www.purebasic.fr/english/

Tip: How to do For/Next with a variable Step
https://www.purebasic.fr/english/viewtopic.php?f=12&t=9839
Page 1 of 1

Author:  PB [ Fri Mar 12, 2004 4:51 am ]
Post subject:  Tip: How to do For/Next with a variable Step

Code updated for 5.20+

I thought I posted this as a standalone tip before, but I can't find it now...
so here it is again. (I originally had it posted as part of this longer thread:
http://forums.purebasic.com/english/vie ... php?t=4930).

Code:
; Example of 'For a=1 To 40 Step b' in PureBasic,
; because you can't use variables for 'Step' yet.

b = 2            ;The 'Step' value (normally a constant!).
For a = 1 To 40
  Debug a        ;Do whatever processing on 'a' here.
  a + b - 1      ;This MUST go directly before 'Next'!
Next

Author:  scurrier [ Fri Mar 12, 2004 1:36 pm ]
Post subject: 

this is out of the help

For : Next

Syntax

For <variable> = <expression1> To <expression2> [Step <constant>]
...
Next [<variable>]

or is this just for windows and not linux?

Sean

Author:  LarsG [ Fri Mar 12, 2004 1:38 pm ]
Post subject: 

I think that PB meant this as a way of having the Step value variable, instead of a constant.. :)

Author:  scurrier [ Fri Mar 12, 2004 1:41 pm ]
Post subject: 

i think i know what your talking about now
but you can do this

#stp=2
For x =1 To 100 Step #stp
Debug x
Next

Author:  LarsG [ Fri Mar 12, 2004 2:12 pm ]
Post subject: 

scurrier wrote:
i think i know what your talking about now
but you can do this

#stp=2
For x =1 To 100 Step #stp
Debug x
Next


Yes, but #stp=2 is still a constant...
I believe PB meant it like this..:
(just a pseudo example)
Code:
if a = 1
    b = 2
else
    b = 1
endif
for i = 1 to 100 ;"step b" won't work here...
    ; code here.. blah blah
    i + b - 1
next

Author:  TronDoc [ Sat Mar 13, 2004 3:23 am ]
Post subject:  Re: Tip: How to do For/Next with a variable Step

PB wrote:
so here it is again.
nice tip. thank you. --jb

Page 1 of 1 All times are UTC + 1 hour
Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
http://www.phpbb.com/