Scripting Helpers is winding down operations and is now read-only. More info→
Ad
Log in to vote
-1

How do I stop a for i = 90,1,-1 do loop that's inside a while true do loop?

Asked by 5 years ago

I have a for loop looking like this: for i = 90,1,-1 do The for loop is inside a while true do loop When I use break to stop the for loop its stops it after while true do repeats How can I make the for loop stop but when the while loop starts it will work again? Can anyone help me out?

0
You can use the syntax break. This stops a loop saSlol2436 716 — 5y
0
Did you read the details? When I use break it stops it and when the while true do loop starts again it wont work. GroovyFhish 8 — 5y
0
@saSlol2436 "When I use break to stop the for loop its stops it after while true do repeats How can I make the for loop stop but when the while loop starts it will work again?" GroovyFhish 8 — 5y
0
I didn't notice. Sorry for disturbing you saSlol2436 716 — 5y
1
This sounds like an XY problem to me. http://xyproblem.info/ BlueTaslem 18071 — 5y

1 answer

Log in to vote
2
Answered by
chomboghai 2044 Moderation Voter Community Moderator
5 years ago
Edited 5 years ago

Using break will exit the current loop.

Also, you could set a variable and check if that variable is true before running your loop so you can control whether it will run or not.

local runForLoop = true

while true then
    if runForLoop then
        for i = 90, 1, -1 do
            if i == 45 then
                runForLoop = false
                break
            end
        end
    end
    wait()
end

The script above will set runForLoop to false and stop running the loop when i is 45.

If you want the for loop to start working again, simply set runForLoop to true.

0
Doesn't that stop the run WhileLoop? I only want to stop the for loop once anw when the while loop repeats it works again. GroovyFhish 8 — 5y
0
Okay, I edited my script. This should be what you're looking for. chomboghai 2044 — 5y
0
If runForLoop is ever false, there will be an infinite while loop with no waits. fredfishy 833 — 5y
1
I was assuming he has a wait, and other stuff inside the while loop otherwise he would've gone with my initial solution. chomboghai 2044 — 5y
Ad

Answer this question