unexpected problem with for next step loop

Just starting out? Need help? Post your questions and find answers here.
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

unexpected problem with for next step loop

Post by wimapon »

i do translate my Quick Basic FFT routine to Pure Basic.

FOR i = a to b step c

c is a calculated integer value.

I see, Pure Basic needs for c an integer numeric constant...


How can i solve this problem?
User avatar
bembulak
Enthusiast
Enthusiast
Posts: 576
Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria

Re: unexpected problem with for next step loop

Post by bembulak »

Use a While-Loop or a Repeat-Loop instead.
cheers,

bembulak
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: unexpected problem with for next step loop

Post by Rook Zimbabwe »

Bemby's right...

Code: Select all

While a < b
; code to execute here
c = c + stepvalue
Wend
You might also want to set off your code in the [ code ] [ /code ] brackets... (without the space... or just highlight the code segment and press the CODE button in the top of the input window! :D

@bembulak: you need to reload your avatar! :mrgreen:
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
User avatar
bembulak
Enthusiast
Enthusiast
Posts: 576
Joined: Mon Mar 06, 2006 3:53 pm
Location: Austria

Re: unexpected problem with for next step loop

Post by bembulak »

@bembulak: you need to reload your avatar!
:D
Better now? :mrgreen:
cheers,

bembulak
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

Re: unexpected problem with for next step loop

Post by wimapon »

Okee folks,

problem solved.

pitty that for next is not the same as i am used to.

but okee.


thanks !
User avatar
SPP
User
User
Posts: 44
Joined: Sun Mar 04, 2007 10:34 am
Location: BCN - SPAIN

Re: unexpected problem with for next step loop

Post by SPP »

Also you can try this:
(Be careful with the endless loops)

lStep = 2
For i = 0 To 9
Debug i
i + (lStep -1)
Next
The PB community is great... nice to meet you!
User avatar
blueznl
PureBasic Expert
PureBasic Expert
Posts: 6172
Joined: Sat May 17, 2003 11:31 am
Contact:

Re: unexpected problem with for next step loop

Post by blueznl »

After a while you get so used to the while / wend construction that you'll be starting to wonder how you could ever do without it :-)
( PB6.00 LTS Win11 x64 Asrock AB350 Pro4 Ryzen 5 3600 32GB GTX1060 6GB - upgrade incoming...)
( The path to enlightenment and the PureBasic Survival Guide right here... )
wimapon
Enthusiast
Enthusiast
Posts: 290
Joined: Thu Dec 16, 2010 2:05 pm
Location: Delfzijl ( The Netherlands )
Contact:

Re: unexpected problem with for next step loop

Post by wimapon »

Yes Folks,
I know while-wend repeat-until are also usable...but there is always a small naughty problem: works the first value or the last value of "step" yes or no...
but a small test will show that.

but... i am still going...

Thanks again.
User avatar
Rook Zimbabwe
Addict
Addict
Posts: 4322
Joined: Tue Jan 02, 2007 8:16 pm
Location: Cypress TX
Contact:

Re: unexpected problem with for next step loop

Post by Rook Zimbabwe »

Rook Zimbabwe wrote:

Code: Select all

While a < b
; code to execute here
c = c + stepvalue
Wend
wrote that without the ide...

more properly:

Code: Select all

a = 0
b = 100
c = 3 ; for examples sake
while a < b
debug "A = "+str(a)
a = a + c
wend
end
OK still on the road without PB to test it but it should work... If you are having vairiable issues I suggets you debug them to check whats going on...

It may be that you do not set the variables you intend to use INSIDE a procedure as GLOBAL...

@bemby... Looking NICE now! :D
Binarily speaking... it takes 10 to Tango!!!

Image
http://www.bluemesapc.com/
Derek
Addict
Addict
Posts: 2354
Joined: Wed Apr 07, 2004 12:51 am
Location: England

Re: unexpected problem with for next step loop

Post by Derek »

I think you should always use "<=" or ">=" when using steps in a while-wend loop so you don't miss out on the last iteration of the loop.

Code: Select all

a = 0
b = 102
c = 3
While a < b
If a>92
Debug "A = "+Str(a)
EndIf
a = a + c
Wend
Debug ""
a = 0
b = 102
c = 3
While a <= b
If a>92
Debug "A = "+Str(a)
EndIf
a = a + c
Wend
Debug ""
For a=0 To 102 Step 3
If a>92
Debug "A = "+Str(a)
EndIf
Next
Post Reply