|
| 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
|
  |
| Joined: 10 Mar 2013 |
| Total Posts: 482 |
|
| |
|
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 |
|
|
|
| 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 |
|
|
|
| 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 |
|
|
|
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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
|
  |
| 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 |
|
|