unexpected problem with for next step loop
-
wimapon
- Enthusiast

- Posts: 290
- Joined: Thu Dec 16, 2010 2:05 pm
- Location: Delfzijl ( The Netherlands )
- Contact:
unexpected problem with for next step loop
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?
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?
Re: unexpected problem with for next step loop
Use a While-Loop or a Repeat-Loop instead.
cheers,
bembulak
bembulak
- Rook Zimbabwe
- Addict

- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
Re: unexpected problem with for next step loop
Bemby's right...
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! 
@bembulak: you need to reload your avatar!
Code: Select all
While a < b
; code to execute here
c = c + stepvalue
Wend
@bembulak: you need to reload your avatar!
Re: unexpected problem with for next step loop
@bembulak: you need to reload your avatar!
Better now?
cheers,
bembulak
bembulak
-
wimapon
- Enthusiast

- Posts: 290
- Joined: Thu Dec 16, 2010 2:05 pm
- Location: Delfzijl ( The Netherlands )
- Contact:
Re: unexpected problem with for next step loop
Okee folks,
problem solved.
pitty that for next is not the same as i am used to.
but okee.
thanks !
problem solved.
pitty that for next is not the same as i am used to.
but okee.
thanks !
Re: unexpected problem with for next step loop
Also you can try this:
(Be careful with the endless loops)
lStep = 2
For i = 0 To 9
Debug i
i + (lStep -1)
Next
(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!
Re: unexpected problem with for next step loop
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... )
( The path to enlightenment and the PureBasic Survival Guide right here... )
-
wimapon
- Enthusiast

- Posts: 290
- Joined: Thu Dec 16, 2010 2:05 pm
- Location: Delfzijl ( The Netherlands )
- Contact:
Re: unexpected problem with for next step loop
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.
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.
- Rook Zimbabwe
- Addict

- Posts: 4322
- Joined: Tue Jan 02, 2007 8:16 pm
- Location: Cypress TX
- Contact:
Re: unexpected problem with for next step loop
wrote that without the ide...Rook Zimbabwe wrote:Code: Select all
While a < b ; code to execute here c = c + stepvalue Wend
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
It may be that you do not set the variables you intend to use INSIDE a procedure as GLOBAL...
@bemby... Looking NICE now!
Re: unexpected problem with for next step loop
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

