generic image
Processing...
  • Games
  • Catalog
  • Develop
  • Robux
  • Search in Players
  • Search in Games
  • Search in Catalog
  • Search in Groups
  • Search in Library
  • Log In
  • Sign Up
  • Games
  • Catalog
  • Develop
  • Robux
   
ROBLOX Forum » Game Creation and Development » Scripting Helpers
Home Search
 

How do you exit a for loop?

Previous Thread :: Next Thread 
ZeroReality is not online. ZeroReality
Joined: 11 Aug 2010
Total Posts: 20
30 Jan 2013 01:31 PM
for i = 1,10 do
if i == 5 then
*exit for loop*
end
end
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
30 Jan 2013 01:32 PM
break breaks out of the current loop.
Example:

for i = 1, 10 do
print(i)
if i == 5 then
break
end
end

Output:
1
2
3
4
5
Report Abuse
velibor is not online. velibor
Joined: 24 Nov 2009
Total Posts: 1003
30 Jan 2013 01:32 PM
for i = 1,10 do
if i == 5 then
break
end
end

That will exit the loop. You can also use return.
Report Abuse
ZeroReality is not online. ZeroReality
Joined: 11 Aug 2010
Total Posts: 20
30 Jan 2013 01:35 PM
Won't that completely end the script? I want my script to continue after the for loop.
Report Abuse
digpoe is not online. digpoe
Joined: 02 Nov 2008
Total Posts: 9092
30 Jan 2013 01:36 PM
break 'breaks' out of the current loop, such as while true do. return is meant for functions, such as this:

function isPlayer(thing)
return thing:GetPlayerFromCharacter()
end

print(isPlayer(workspace.Player1))
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripting Helpers
   
 
   
  • About Us
  • Jobs
  • Blog
  • Parents
  • Help
  • Terms
  • Privacy

©2017 Roblox Corporation. Roblox, the Roblox logo, Robux, Bloxy, and Powering Imagination are among our registered and unregistered trademarks in the U.S. and other countries.



Progress
Starting Roblox...
Connecting to Players...
R R

Roblox is now loading. Get ready to play!

R R

You're moments away from getting into the game!

Click here for help

Check Remember my choice and click Launch Application in the dialog box above to join games faster in the future!

Gameplay sponsored by:
Loading 0% - Starting game...
Get more with Builders Club! Join Builders Club
Choose Your Avatar
I have an account
generic image