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

What is the Break Variable?

Asked by
IcyEvil 260 Moderation Voter
10 years ago

I saw it on a Lua Teaching Game, I didnt Know that it was a Variable, I think from its name it works like Remove, or Destroy, Except it Breaks things, Am I correct if not Give me an example?

1 answer

Log in to vote
1
Answered by
adark 5487 Badge of Merit Moderation Voter Community Moderator
10 years ago

break is not a variable, it is a 'keyword', which is why it is colored blue in the script editor.

break is used to, as the name implies, break out of a loop before its condition would otherwise allow.

For example:

local var = 0
while var < 20 do
    var = var + 1
    wait()
end

and

local var = 0
while true do
    var = var + 1
    if var >= 20 then
        break
    end
end

are functionally identical.

A practical use of break is quitting a Murder-type game's loop when the Murderer is killed or otherwise leaves the game.

Ad

Answer this question