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
|
  |
| 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 |
|
|
|
| 06 Oct 2015 08:37 PM |
| What does the contuine keywoprd do? |
|
|
| Report Abuse |
|
|
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
|
  |
| 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
|
  |
| 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 |
|
|
|
| 06 Oct 2015 08:43 PM |
'tis what return does, don't she?
morashsPeasant is standing |
|
|
| Report Abuse |
|
|
|
| 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
|
  |
| 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 |
|
|
|
| 06 Oct 2015 08:44 PM |
| ^return stops everything in the function |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 06 Oct 2015 08:46 PM |
| ^ I was telling that one guy how it workeded |
|
|
| Report Abuse |
|
|
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
|
  |
| 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 |
|
|
|
| 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 |
|
|
|
| 06 Oct 2015 08:48 PM |
for i = 1, 100 do function loop() return end loop() end |
|
|
| Report Abuse |
|
|
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 |
|
|
|
| 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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
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 |
|
|
|
| 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
|
  |
| 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
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
|
| 06 Oct 2015 08:55 PM |
| Nope they all suck, mine is better!1 |
|
|
| Report Abuse |
|
|
|
| 06 Oct 2015 08:56 PM |
| http://pastebin.com/0VN1Dizf |
|
|
| Report Abuse |
|
|