Page 1 of 1

for...next...step

Posted: Fri Mar 01, 2013 4:01 am
by ivega718
How I can do that variable incr in decimal values?

Code: Select all


Define X.d
For X.d=1 To 2 Step .5
  MessageRequester ("",Str(X.d))  
Next X.d

Code: Select all

Define x.d
x.d=0
Repeat
  x.d=x.d + .5
  MessageRequester("",Str(x.d)) 
Until x.d=3
This not compile...somebody know of other alternative?

sorry...I am new in PureBasic...

Re: for...next...step

Posted: Fri Mar 01, 2013 4:13 am
by jassing
Use strf()...

Re: for...next...step

Posted: Fri Mar 01, 2013 4:15 am
by STARGĂ…TE
For : Next: Step is only for integers!
if you need a loop with floats/doubles you can use a While : Wend loop:

if you debug a float/double, you have to use StrF/StrD() instead of Str()

Code: Select all

Define X.d = 1.0

While X <= 2.0
  MessageRequester("", StrD(X))
  X + 0.5
Wend

Re: for...next...step

Posted: Fri Mar 01, 2013 4:20 am
by IdeasVacuum

Code: Select all

Define X.d = 0

While(X < 2.4)

     MessageRequester ("",StrD(X))
     X = X + 0.5
 
Wend

End
For loops can only use integer steps.

Re: for...next...step

Posted: Fri Mar 01, 2013 4:37 am
by ts-soft

Code: Select all

Define x.d = 0
Repeat
  x + 0.5
  MessageRequester("", StrD(x))
Until x = 3

Re: for...next...step

Posted: Fri Mar 01, 2013 7:20 am
by ivega718
This forum is wonderful...I am learning and more I know I like this compiler...

Now is working fine...

Thanks

Re: for...next...step

Posted: Fri Mar 01, 2013 10:46 am
by GWS
In the FOR loop, work in tenths, hundreths or whatever you require .. :)

This example runs between 1.0 and 2.0 in tenths:

Code: Select all

OpenConsole()
ClearConsole()

For i = 10 To 20

  PrintN(StrF((i/10),1))

Next i

PrintN("Press any key to exit")
Input()
PrintN("Done")
Delay(2000)

End
best wishes, :)

Graham