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

All times are UTC + 1 hour




Post new topic Reply to topic  [ 21 posts ]  Go to page 1, 2  Next
Author Message
 Post subject:
PostPosted: Mon Jan 27, 2003 11:54 pm 
Offline
PureBasic Guru
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
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 28, 2003 1:09 am 
Offline
PureBasic Guru
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
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 28, 2003 10:11 am 
Offline
PureBasic Guru
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
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 28, 2003 12:47 pm 
Offline
PureBasic Guru
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
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 28, 2003 2:56 pm 
Offline
PureBasic Guru
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
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Jan 28, 2003 3:01 pm 
Offline
PureBasic Guru
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
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 18, 2003 5:07 pm 
Offline
User
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
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 18, 2003 6:35 pm 
Offline
Administrator
Administrator

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


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 18, 2003 8:42 pm 
Offline
PureBasic Expert
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
 Profile  
Reply with quote  
 Post subject:
PostPosted: Tue Nov 18, 2003 11:27 pm 
Offline
User
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
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 27, 2003 4:22 am 
Offline
PureBasic Expert
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
 Profile  
Reply with quote  
 Post subject:
PostPosted: Thu Nov 27, 2003 3:46 pm 
Offline
PureBasic Expert
PureBasic Expert
User avatar

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
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Nov 28, 2003 4:28 am 
Offline
PureBasic Expert
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? :lol:


Top
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Nov 28, 2003 12:19 pm 
Offline
Enthusiast
Enthusiast
User avatar

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
 Profile  
Reply with quote  
 Post subject:
PostPosted: Fri Nov 28, 2003 12:59 pm 
Offline
Enthusiast
Enthusiast
User avatar

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
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 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 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