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
 

Re: Is there any way out of a "while true do" loop?

Previous Thread :: Next Thread 
NeoEclipse is not online. NeoEclipse
Joined: 09 Apr 2012
Total Posts: 5407
12 Apr 2014 03:27 PM
Maybe lets say you're counting up. And if something happens then it stops counting up.

I don't think this can be accomplished with a for loop?
Report Abuse
kokasnuts is not online. kokasnuts
Joined: 10 Mar 2013
Total Posts: 482
12 Apr 2014 03:27 PM
loop until

return until
Report Abuse
youssef04 is not online. youssef04
Joined: 22 Jan 2011
Total Posts: 1745
12 Apr 2014 03:29 PM
????????????????????
Like this:
while wait() do
i = 10, 0, 1
wait(1)
print[i]
end

I haven't tried, maybe it would work.
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
12 Apr 2014 03:30 PM
^ ??


while (CONDITION) do
-- stuff
end


Runs every time CONDITION is true when the loop starts.


break


From inside the loop, it will end the loop immediately and run stuff outside the loop.




repeat
-- stuff
until CONDITION



Same as a while loop, except it's a "post-test" loop, meaning the loop is guaranteed to run at least once. A "pre-test" loop is NOT guaranteed to run at least once (while loops are pre-test loops).
Report Abuse
AgentFirefox is not online. AgentFirefox
Top 100 Poster
Joined: 20 Jun 2008
Total Posts: 22404
12 Apr 2014 03:32 PM
"repeat
-- stuff
until CONDITION



Same as a while loop, except it's a "post-test" loop, meaning the loop is guaranteed to run at least once. A "pre-test" loop is NOT guaranteed to run at least once (while loops are pre-test loops)."


It isn't exactly like the while loop, because the loop repeats until CONDITION is true. This means the loop runs only while CONDITION is false. Apologies.
Report Abuse
cody123454321 is not online. cody123454321
Joined: 21 Nov 2009
Total Posts: 5408
12 Apr 2014 03:37 PM
repeat wait(2) until condition

where wait(2) would be your function to run, or your methods.
and condition is such as an if statement:

if(true)then -- must be true to run
end

if(not true)then -- must be false to run
end

...

Inside of a while loop:

while true do
end

you must use break. This will stop the loop in it's tacks without running the rest of it.

while true do
break
end
Report Abuse
RoflBread is not online. RoflBread
Joined: 18 Jun 2009
Total Posts: 3803
12 Apr 2014 03:45 PM
a=0
while true do
a = a +1
if a>= 10 then
break
end
end
Report Abuse
gamehero is not online. gamehero
Joined: 12 Jun 2007
Total Posts: 1455
12 Apr 2014 03:48 PM
Why not use a for loop? Is there a reason why? It's cleaner than using a while loop to count.

for a=1,10 do
wait(0.5)
print(a)
end
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
12 Apr 2014 03:49 PM
-- As stated before

local a = 0
while wait() and not a >= 10 do
a = a + 1
print(a)
end

local a = 0
repeat a = a + 1
print(a)
wait()
until not a >= 10
Report Abuse
Bebee2 is not online. Bebee2
Joined: 17 May 2009
Total Posts: 3985
12 Apr 2014 03:50 PM
@Game, he wants it to be triggered off rather than set to turn off.
Report Abuse
gamehero is not online. gamehero
Joined: 12 Jun 2007
Total Posts: 1455
12 Apr 2014 04:04 PM
Oh, it finally clicked. Alright, he's probably asking for this then.


count = workspace.Count -- BoolValue, uncheck it at any time to stop counting.
n = 0

while count.Value do
n = n+1
wait(0.5)
print(n)
end

print("Stopped counting!")
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