View Full Version : jump out from a for/next loop
Pedro Santos
- 9th March 2007, 13:24
Hello
Is this correct if i exit so from a For/next loop
this code make no sense only to descrive the question
For i = 1 to 100
high led
pause 1000
low led
if i >= 30 then exit 'can i jump out from the loop? in other language exixts
'the instruction "break"
next
exit:
'
'
end
regards
Pedro
BobK
- 9th March 2007, 13:59
Hi Pedro,
Why would you set a loop "for i = 1 to 100" if your going to exit the loop after 30 counts? I could possibly understand putting an "if-then" situation in there if you needed to do something based on a condition of another input or something but your example doesn't make any sense.
BobK
Pedro Santos
- 9th March 2007, 15:10
Hi BobK
I said that the example no make sense, the question is if i can without stack
or other problems jump out of the for/next loop
again
For i = 1 To 100
high led
pause 200
low led
pause 200
If PORTB.3 = 1 then exit
next
exit:
end
or is this better?
For i = 1 To 100
high led
pause 200
low led
pause 200
If PORTB.3 = 1 then i = 100
next
regards
Pedro
Bruce
- 9th March 2007, 15:50
Hi Pedro,
It's perfectly OK to exit a FOR/NEXT loop like in your examples.
Powered by vBulletin® Version 4.1.7 Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.