It is currently Sat Aug 24, 2019 1:33 am

All times are UTC + 1 hour




Post new topic Reply to topic  [ 6 posts ] 
Author Message
 Post subject: Tip: How to do For/Next with a variable Step
PostPosted: Fri Mar 12, 2004 4:51 am 
Offline
PureBasic Expert
PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Mar 12, 2004 1:36 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat May 03, 2003 4:10 am
Posts: 169
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Mar 12, 2004 1:38 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jun 02, 2003 1:06 pm
Posts: 713
Location: Norway
I think that PB meant this as a way of having the Step value variable, instead of a constant.. :)

_________________

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Mar 12, 2004 1:41 pm 
Offline
Enthusiast
Enthusiast

Joined: Sat May 03, 2003 4:10 am
Posts: 169
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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Mar 12, 2004 2:12 pm 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Mon Jun 02, 2003 1:06 pm
Posts: 713
Location: Norway
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

_________________

AMD Athlon XP2400, 512 MB RAM, Hercules 3D Prophet 9600 256MB RAM, WinXP
PIII 800MHz, 320 MB RAM, Nvidia Riva Tnt 2 Mach 64 (32MB), WinXP + Linux
17" iMac, 1.8 GHz G5, 512 MB DDR-RAM, 80 GB HD, 64 MB Geforce FX 5200, SuperDrive, OSX


Top
 Profile  
Reply with quote  
 Post subject: Re: Tip: How to do For/Next with a variable Step
PostPosted: Sat Mar 13, 2004 3:23 am 
Offline
Enthusiast
Enthusiast
User avatar

Joined: Wed Apr 30, 2003 3:50 am
Posts: 310
Location: 3DoorsDown
PB wrote:
so here it is again.
nice tip. thank you. --jb


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC + 1 hour


Who is online

Users browsing this forum: No registered users and 6 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
Jump to:  

 


Powered by phpBB © 2008 phpBB Group
subSilver+ theme by Canver Software, sponsor Sanal Modifiye