for...next...step

Just starting out? Need help? Post your questions and find answers here.
ivega718
User
User
Posts: 15
Joined: Mon Feb 25, 2013 9:29 pm

for...next...step

Post 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...
jassing
Addict
Addict
Posts: 1885
Joined: Wed Feb 17, 2010 12:00 am

Re: for...next...step

Post by jassing »

Use strf()...
User avatar
STARGÅTE
Addict
Addict
Posts: 2227
Joined: Thu Jan 10, 2008 1:30 pm
Location: Germany, Glienicke
Contact:

Re: for...next...step

Post 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
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
IdeasVacuum
Always Here
Always Here
Posts: 6426
Joined: Fri Oct 23, 2009 2:33 am
Location: Wales, UK
Contact:

Re: for...next...step

Post 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.
IdeasVacuum
If it sounds simple, you have not grasped the complexity.
User avatar
ts-soft
Always Here
Always Here
Posts: 5756
Joined: Thu Jun 24, 2004 2:44 pm
Location: Berlin - Germany

Re: for...next...step

Post by ts-soft »

Code: Select all

Define x.d = 0
Repeat
  x + 0.5
  MessageRequester("", StrD(x))
Until x = 3
PureBasic 5.73 | SpiderBasic 2.30 | Windows 10 Pro (x64) | Linux Mint 20.1 (x64)
Old bugs good, new bugs bad! Updates are evil: might fix old bugs and introduce no new ones.
Image
ivega718
User
User
Posts: 15
Joined: Mon Feb 25, 2013 9:29 pm

Re: for...next...step

Post by ivega718 »

This forum is wonderful...I am learning and more I know I like this compiler...

Now is working fine...

Thanks
User avatar
GWS
User
User
Posts: 23
Joined: Tue Sep 27, 2005 9:51 pm
Location: Staffs. UK

Re: for...next...step

Post 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
Tomorrow may be too late ..
Post Reply