# PureBasic Forum

 It is currently Tue Mar 31, 2020 8:45 pm

 All times are UTC + 1 hour

 Page 1 of 2 [ 21 posts ] Go to page 1, 2  Next
 Print view Previous topic | Next topic
Author Message
 Post subject: Posted: Mon Jan 27, 2003 11:54 pm
 PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by ebs.

Fred,

I don't know if this was requested before, but please make the Step value in a For...Next loop a *variable*, not a constant. I often want to set the step based on other variables, and also be able to "reverse direction" in the loop by using: "StepValue = -StepValue".

Regards,
Eric

Top

 Post subject: Posted: Tue Jan 28, 2003 1:09 am
 PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by VPureBasic.

Hi ebs,

Why you did not try something like...

For x = A to B step C
...
...
Next x

A = ( your start )
B = ( your limit )
C = ( your step value )

Roger

Top

 Post subject: Posted: Tue Jan 28, 2003 10:11 am
 PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by PB.

> Why you did not try something like...
> For x = A to B step C

Doesn't work. Compiler complains about C not being a constant.

Top

 Post subject: Posted: Tue Jan 28, 2003 12:47 pm
 PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by tinman.

Quote:
Originally posted by ebs

I don't know if this was requested before, but please make the Step value in a For...Next loop a *variable*, not a constant. I often want

Better making it an expression (so you can do e.g. "... Step foo+bar(blah)"

--
It's not minimalist - I'm increasing efficiency by reducing input effort.
(Win98first ed. + all updates, PB3.50)

Top

 Post subject: Posted: Tue Jan 28, 2003 2:56 pm
 PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by Kendrel.

actually it works if the step variable is a constant or a fixed number... but it would be nice if one could also use a variable.

my 2 cents

kendrel

Top

 Post subject: Posted: Tue Jan 28, 2003 3:01 pm
 PureBasic Guru

Joined: Tue Apr 22, 2003 7:42 pm
Posts: 16777133
Restored from previous forum. Originally posted by fred.

I take good notes.

Fred - AlphaSND

Top

 Post subject: Posted: Tue Nov 18, 2003 5:07 pm
 User

Joined: Mon Oct 06, 2003 1:42 am
Posts: 22
Fred, is this feature in the next version? or can it still be added if it is not?

_________________
Thanks,
Master Games

System: P4 1.9 GHZ, 1 GB DDR Memory, 80 GB Hard Drive, WinXP Home Edition with Latest Patch, Creative labs Audigy Sound Blaster Platinum Sound Card, Geforce 3 Graphics card with 52.16 drivers

Top

 Post subject: Posted: Tue Nov 18, 2003 6:35 pm

Joined: Fri May 17, 2002 4:39 pm
Posts: 14011
Location: France
Not implemented for now...

Top

 Post subject: Posted: Tue Nov 18, 2003 8:42 pm
 PureBasic Expert

Joined: Fri Apr 25, 2003 6:41 pm
Posts: 1356
Fred wrote:
Not implemented for now...

But would be a good idea (and i can't imagine, that it is a big problem)

Top

 Post subject: Posted: Tue Nov 18, 2003 11:27 pm
 User

Joined: Mon Oct 06, 2003 1:42 am
Posts: 22
GPI wrote:
Fred wrote:
Not implemented for now...

But would be a good idea (and i can't imagine, that it is a big problem)

I second that! Since C allows you to do it.

_________________
Thanks,
Master Games

System: P4 1.9 GHZ, 1 GB DDR Memory, 80 GB Hard Drive, WinXP Home Edition with Latest Patch, Creative labs Audigy Sound Blaster Platinum Sound Card, Geforce 3 Graphics card with 52.16 drivers

Top

 Post subject: Posted: Thu Nov 27, 2003 4:22 am
 PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
Until Fred implements 'Step' as a variable, you can always do it like this:

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

 Post subject: Posted: Thu Nov 27, 2003 3:46 pm
 PureBasic Expert

Joined: Sat May 17, 2003 11:31 am
Posts: 6073
oh, pb, use repeat until or while wend instead! brrr...

; for a = 1 to 40 step b

a = 1
while a+b <= 40
; whatever
a = a+b
wend

or

a=1
repeat
; whatever
a = a+b
until a > 40

_________________
( PB5.xx Win10 x64 Asrock AB350 Pro4 Ryzen 1600X 32GB RAM Evo 840 GTX1060 )
( The path to enlightenment and the PureBasic Survival Guide right here... )

Top

 Post subject: Posted: Fri Nov 28, 2003 4:28 am
 PureBasic Expert

Joined: Fri Apr 25, 2003 5:24 pm
Posts: 7581
> use repeat until or while wend instead

But then it's not a For/Next loop with a variable anymore, is it?

Top

 Post subject: Posted: Fri Nov 28, 2003 12:19 pm
 Enthusiast

Joined: Wed Oct 29, 2003 10:35 am
Posts: 537
For - Next works well as it is
While - Wend and repeat - until can do the step.....

Everythings quick !

Why change a winning formula ?

This isn't TrueBasic, or a TRUE Basic, it's a very fast basic !

Why do we need the variable step, if it will slow the loop down ?

_________________
Paid up PB User !

Top

 Post subject: Posted: Fri Nov 28, 2003 12:59 pm
 Enthusiast

Joined: Fri Apr 25, 2003 5:22 pm
Posts: 423
Of course the compiler could&should watch for the step-parameter if it is a const or a variable and then compile to the fast loop as always if it is a const or to another loop if it is a variable...

Anyway, I personally don't need step-variables, it would only be a nice gimmick.

_________________
%1>>1+1*1/1-1!1|1&1<<\$1=1

Top

 Display posts from previous: All posts1 day7 days2 weeks1 month3 months6 months1 year Sort by AuthorPost timeSubject AscendingDescending
 Page 1 of 2 [ 21 posts ] Go to page 1, 2  Next

 All times are UTC + 1 hour

#### Who is online

Users browsing this forum: No registered users and 5 guests

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

Search for:
 Jump to:  Select a forum ------------------ PureBasic    Coding Questions    Game Programming    3D Programming    Assembly Programming    The PureBasic Editor    The PureBasic Form Designer    General Discussion    Feature Requests and Wishlists    Tricks 'n' Tips Bug Reports    Bugs - Windows    Bugs - Linux    Bugs - Mac OSX    Bugs - Documentation OS Specific    AmigaOS    Linux    Windows    Mac OSX Miscellaneous    Announcement    Off Topic Showcase    Applications - Feedback and Discussion    PureFORM & JaPBe    TailBite