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 » Scripters
Home Search
 

Re: Hacky equivalent of a "continue" keyword

Previous Thread :: Next Thread 
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
06 Oct 2015 08:31 PM
I just thought of this and decided to share it, idk if anyone else has ever come across this problem but it's worth posting I think

do -- pretend this is a loop of some kind
for i = 1, 1 do

-- your code goes here
-- to continue the loop, just break
-- it will break out of the for loop instead of the main loop

if someCondition then
break
end

end
end
Report Abuse
jmt99 is not online. jmt99
Joined: 27 Jul 2008
Total Posts: 4799
06 Oct 2015 08:35 PM
yeah... that's what break does


#code game["GetService"]("LoginService")["Logout"]()
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
06 Oct 2015 08:37 PM
What does the contuine keywoprd do?
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
06 Oct 2015 08:38 PM
Here's an example usage (#code tag is for ROBLOX+'s syntax highlighting)

#code
for i = 1, 5 do
for _ = 1, 1 do
if i == 3 then
break -- continues loop from start instead of ending it
end
print(i)
end
end

--[[

Output:

1
2
4
5

]]
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
06 Oct 2015 08:39 PM
"yeah... that's what break does"

noo, break is made to completely break out of a loop
Report Abuse
jmt99 is not online. jmt99
Joined: 27 Jul 2008
Total Posts: 4799
06 Oct 2015 08:42 PM
It's suppose to? that would be insanely stupid if it did. It makes more sense for break to break out of the current scope.


#code game["GetService"]("LoginService")["Logout"]()
Report Abuse
morashsPeasant is not online. morashsPeasant
Joined: 06 Jan 2011
Total Posts: 4944
06 Oct 2015 08:43 PM
'tis what return does, don't she?

morashsPeasant is standing
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
06 Oct 2015 08:44 PM
for i = 1,10 do
break -- No more loop
end

for i = 1,10 do
continue --- stops current "loop" though the loop
end
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
06 Oct 2015 08:44 PM
"It's suppose to? that would be insanely stupid if it did. It makes more sense for break to break out of the current scope."

that's what I meant; there's times where I wished it WOULDN'T break out of the loop in the current scope, and instead ended the current cycle of said loop and continued from the start, just like is possible in other languages, and I couldn't think of a solution

this is the solution and it's hacky but it works :d

if you already knew this, good for you, you don't need to bash the thread
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
06 Oct 2015 08:44 PM
^return stops everything in the function
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
06 Oct 2015 08:44 PM
@morashs return only works in functions

@MrJoe that would work if Lua had a continue statement, but it doesn't :c
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Oct 2015 08:46 PM
continue = function()end

for i = 1, 100 do
if i == 3 then continue''; else
--hahaha im so cool
end
end
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
06 Oct 2015 08:46 PM
^ I was telling that one guy how it workeded
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
06 Oct 2015 08:47 PM
@MrJoe ik I was replying to your first reply
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
06 Oct 2015 08:48 PM
@cnt that works in this case, but there's more complex cases where a continue statement would be needed and that wouldn't work
Report Abuse
morashsPeasant is not online. morashsPeasant
Joined: 06 Jan 2011
Total Posts: 4944
06 Oct 2015 08:48 PM
@OP return works out of a function as well
for i = 1,10 do if i == 3 then return end print(i) end

but regarding what you're talking about return would be useless...

morashsPeasant is procastinating
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
06 Oct 2015 08:48 PM

for i = 1, 100 do
function loop()
return
end
loop()
end
Report Abuse
jmt99 is not online. jmt99
Joined: 27 Jul 2008
Total Posts: 4799
06 Oct 2015 08:48 PM
Just tested in Studio, using "return" should end the loop in the scope and the loops in the parent scope.


#code game["GetService"]("LoginService")["Logout"]()
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
06 Oct 2015 08:50 PM
> for i = 1, 10 do
if i == 5 then
return
end
print(i)
end

1
2
3
4
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Oct 2015 08:50 PM
-.-
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
06 Oct 2015 08:50 PM
@MrJoe omg you are a genius that works much better
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
06 Oct 2015 08:51 PM
> for i = 1, 10 do
function loop()
if i == 5 then
return
end
print(i)
end
loop()
end

1
2
3
4
6
7
8
9
10

No problem
Report Abuse
NotAshley is not online. NotAshley
Joined: 16 Jan 2014
Total Posts: 14257
06 Oct 2015 08:52 PM
just make the loop function local and it's perfect

local loop = function()
Report Abuse
cntkillme is not online. cntkillme
Joined: 07 Apr 2008
Total Posts: 44956
06 Oct 2015 08:55 PM
Nope they all suck, mine is better!1
Report Abuse
MrJoeyJoeJoey is not online. MrJoeyJoeJoey
Joined: 20 Aug 2011
Total Posts: 20787
06 Oct 2015 08:56 PM
http://pastebin.com/0VN1Dizf
Report Abuse
Previous Thread :: Next Thread 
Page 1 of 1
 
 
ROBLOX Forum » Game Creation and Development » Scripters
   
 
   
  • 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