STEP Variable !

Got an idea for enhancing PureBasic? New command(s) you'd like to see?
User avatar
GeBonet
Enthusiast
Enthusiast
Posts: 135
Joined: Fri Apr 04, 2008 6:20 pm
Location: Belgium

STEP Variable !

Post by GeBonet »

Hi !
Now for the STEP in the FOR/NEXT is a constant and Integer !
How to do, if the Step is dependent on a result from the code ? And more, if is not integer ?
As in other language, whether the STEP must be VARIABLE

Maintenant, le PAS dans une boucle FOR/NEXT doit être une constante et de plus entier.

Comment faire si le PAS est dépendant d'un RESULTAT qui peut être décimal = 0.02 ??? Ou autre ?
Dans d'autre language c'est possible... Alors PB non ?
Merci.
Sorry for my english :wink: ! (Windows Xp, Vista and Windows 7, Windows 10)
gnasen
Enthusiast
Enthusiast
Posts: 282
Joined: Wed Sep 24, 2008 12:21 am

Re: STEP Variable !

Post by gnasen »

For this case you normally use a While : Wend complex. I never noticed in another language if it is possible, however I wouldnt think its necessary.
pb 5.11
User avatar
Demivec
Addict
Addict
Posts: 4257
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: STEP Variable !

Post by Demivec »

GeBonet wrote:Hi !
Now for the STEP in the FOR/NEXT is a constant and Integer !
How to do, if the Step is dependent on a result from the code ? And more, if is not integer ?
As in other language, whether the STEP must be VARIABLE

Code: Select all

myStep.f = 0.2
i.f = 1.0
Repeat
  Debug i
  ;myStep + 0.1   ;variable step
  i + myStep
Until i > 10.0

Debug "----"

myStep.f = 0.2
i.f = 1.0
While i <= 10.0
  Debug i
  ;myStep + 0.1   ;variable step
  i + myStep
Wend
@Edit: I updated the work-around to use floats. :wink:
Last edited by Demivec on Mon Sep 05, 2011 12:35 am, edited 1 time in total.
User avatar
GeBonet
Enthusiast
Enthusiast
Posts: 135
Joined: Fri Apr 04, 2008 6:20 pm
Location: Belgium

Re: STEP Variable !

Post by GeBonet »

HI !
I Thing you not have understand what i mind !
If i one part of the code give me 0.05 and this value is the STEP for a evolution of the space between 2 limits into one curve...
The sample code :
VariationOffCode=0.05
For i=lowLimit TO Highlimit STEP VariationOffCode
Result(k)=value*sin(angle+i):k+1
next i

Therefore, we need "i" and the value of STEP must be floating or double precision ...
Or it would be easier! :wink:
Note : There are obviously other way to get around this, but it would be a bypass, i know this and tanks. :D
Sorry for my english :wink: ! (Windows Xp, Vista and Windows 7, Windows 10)
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: STEP Variable !

Post by STARGÅTE »

swap i and k:

Code: Select all

VariationOffCode.f=0.05
maxk = (Highlimit-lowLimit)/VariationOffCode
i.f = lowLimit
For k=0 To maxk
	Result(k)=value*Sin(angle+i) : i+VariationOffCode
Next k
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
User avatar
GeBonet
Enthusiast
Enthusiast
Posts: 135
Joined: Fri Apr 04, 2008 6:20 pm
Location: Belgium

Re: STEP Variable !

Post by GeBonet »

Thank you, thank you very much
But here it is "Feature Requests and Wishlists" and that's what I want!
Just One for Sample : "For i.f = 2.5 to 25.5 Step 0.5"
and the 0.5 can be given by a variable is all ...
Tanks you.
Sorry for my english :wink: ! (Windows Xp, Vista and Windows 7, Windows 10)
User avatar
STARGÅTE
Addict
Addict
Posts: 2226
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: STEP Variable !

Post by STARGÅTE »

you can not increment floats!!

Example:
From 0.00 to 1.00 in 0.02 steps you need 50 steps right ?
but look this:

Code: Select all

Count = 0
Float.f = 0.00
While Float <= 1.00
	Count + 1
	Float + 0.02
	Debug Float
Wend
Debug "---"
Debug "steps: "+Str(Count)
Debug "---"
problem here: +0.02 not finished by 1.00 !!!
it finished at 0.99999958276749 and thats smaler then 1.0, so +1 step
PB 6.01 ― Win 10, 21H2 ― Ryzen 9 3900X, 32 GB ― NVIDIA GeForce RTX 3080 ― Vivaldi 6.0 ― www.unionbytes.de
Lizard - Script language for symbolic calculations and moreTypeface - Sprite-based font include/module
Post Reply