Jump to content

Return break


Msypon

Recommended Posts

The return keyword should be used to return a value in a function, or stop it (simply use the keyword with no value). The break keyword is used to stop loops (do, while, repeat).

And for example:

break :

for i,v in ipairs{1, 2, 3, 4, 5} do -- looping table 
    if v == 2 then -- checking if the value is "2" while looping 
        break -- breaking/stopping loop 
        outputDebugString("Loop broken") -- outputs to debug 
    end 
end 

return :

function outputToChat(text) -- function you can call anytime you want 
    if text:lower():find("ixjf is nice") then -- if it found a similar word like this then 
        return outputChatBox("That's a lie!") -- it will stop the function from outputting the text and outputs this 
    end 
    outputChatBox(text) -- outputting to chat box the text message you've passed to the function 
end 

Link to comment

Your break example is wrong, break has to go after your code inside the loop, like this:

for i,v in ipairs{1, 2, 3, 4, 5} do -- looping table 
    if v == 2 then -- checking if the value is "2" while looping 
        outputDebugString("Loop broken") -- outputs to debug 
        break -- breaking/stopping loop 
    end 
end 

Link to comment
Your break example is wrong, break has to go after your code inside the loop, like this:
for i,v in ipairs{1, 2, 3, 4, 5} do -- looping table 
    if v == 2 then -- checking if the value is "2" while looping 
        outputDebugString("Loop broken") -- outputs to debug 
        break -- breaking/stopping loop 
    end 
end 

uhm, k, thanks dude

Link to comment

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...