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

How would I break this loop without it erroring?

Asked by
Discern 1007 Moderation Voter
10 years ago

So I just made this as an example, but the concept is the same.

How would I break this while loop without an error??

while true do
    if 2 > 1 then --Always True
        break
    end
    wait(1)
end

This concept is in my game script. The output says "end" expected near "if" at line [LINENUMBER], [LINENUMBER] being the line number of my if statement.

The problem is, there ARE enough ends. There are 2 ends; 1 for the if statement, 1 for the while loop. I will have to remake my entire game script if I can't find out a way. In the game script, the if statement is actually needed, and the break HAS to be inside of the if statement.

2 answers

Log in to vote
0
Answered by 10 years ago

What are you trying to accomplish here by breaking the while loop? I will need a bit more of your script to be able to understand the point of the while loop in the first place.

0
Here is the script. The breaks are at line 220. Discern 1007 — 10y
Ad
Log in to vote
0
Answered by
Dummiez 360 Moderation Voter
10 years ago

Use a variable instead of true. Once run is 'false', the while do statement will no longer be true and end the loop. You can return to the loop when run is set to 'true' again

local run = true

    while run do
    if 2 > 1 then -- Always true
        run = true -- When run is 'false' the loop will break
    end
end
0
Thanks, but my while loop is actually being used for multiples of things, and I already used the while [CONDITION] setting. It is not while true do in my script. Discern 1007 — 10y
0
You should have mentioned this in your question. Why didn't you do it? Dummiez 360 — 10y
0
You are also missing numerous information from your script. [LINENUMBER] doesn't help. Dummiez 360 — 10y

Answer this question