IcyFires
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 5046 |
|
|
| 08 Oct 2014 03:03 PM |
After some studies conducted by me, I have determined the repeat loop is hated on for no reason. This alliance's goal is to promote using repeat loops instead of while loops in the appropriate places such as conditions that never terminate the loop. For instance:
What to use-
repeat wait() --code-- until nil
What not to use-
while wait() do --Or while (something that is true) do wait() --code-- end
Pledge to join the alliance below
IcyFires - - - - - - - - - |
|
|
| Report Abuse |
|
|
TheMyrco
|
  |
| Joined: 13 Aug 2011 |
| Total Posts: 15105 |
|
|
| 08 Oct 2014 03:04 PM |
I use about equally as much repeat-untils as while-ends ...
MYRCO - 더는 낭의 꿍에 갇혀 살시 아。- MYRCO |
|
|
| Report Abuse |
|
|
IcyFires
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 5046 |
|
|
| 08 Oct 2014 03:06 PM |
| I've never ever seen anyone else use a repeat loop except to wait for LocalPlayer. I have seen plenty of while loops though. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 08 Oct 2014 03:13 PM |
| A repeat loop is similar to a do while loop, and hopefully you know what that is. Don't be one of those people that try to force in do...whiles where they don't belong. |
|
|
| Report Abuse |
|
|
IcyFires
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 5046 |
|
|
| 08 Oct 2014 03:17 PM |
| I know that a repeat loop executes the code once before checking the condition and a while loop checks it first, That is why I specifically mentioned never terminating loops because it doesn't matter if it is executed once before checking the condition in this scenario. |
|
|
| Report Abuse |
|
|
| |
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 08 Oct 2014 03:21 PM |
| "...it doesn't matter if it is executed once before checking the condition in this scenario." Yes but this is almost always semantically incorrect. If it's an infinite loop (stop calling them never terminating loops) then that does not mean you should immediately run the code first without checking. |
|
|
| Report Abuse |
|
|
IcyFires
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 5046 |
|
|
| 08 Oct 2014 03:24 PM |
| No, I mean if you are making a loop that you know you will want to never terminate right then and there. I am not depending this theory on what may happen in game or whatever. I'm saying if you were to make a table of infinite integers, you would know right then and there that the loop would never end, so why not use a repeat loop rather that a while loop? |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 08 Oct 2014 03:31 PM |
"I'm saying if you were to make a table of infinite integers, you would know right then and there that the loop would never end, so why not use a repeat loop rather that a while loop?" Let me answer that question for you, because it is not semantically correct. You use a do while when you want to run the code first without checking but without pasting the exact code above it. Even though it may produce the same result that's not the intended use of a do while. By using a do while in that situation you're just confusing anyone reading it by not using the standard while loop. Now you say "why not use a repeat loop rather that a while loop?" well why use a not use a while loop rather than a repeat loop? I already explained why that'd be better. Also as someone mentioned on another thread, repeat loops don't follow the rest of Lua's syntax. |
|
|
| Report Abuse |
|
|
IcyFires
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 5046 |
|
|
| 08 Oct 2014 03:32 PM |
Not only that, but in this situation, repeat would THEORETICALLY reach infinity faster because since it preforms it's check after it runs the code, it will be approximately 1/100 of a second ahead of the while loop at adding a number to the table.
Notice how I said theoretically, that means it can't actually happen but rather in theory. So don't argue that point. |
|
|
| Report Abuse |
|
|
IcyFires
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 5046 |
|
|
| 08 Oct 2014 03:34 PM |
| So it's a matter of aesthetics for you, it doesn't matter if it makes it easier for anyone to read. If it works as intended, why not? |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 08 Oct 2014 03:40 PM |
"So it's a matter of aesthetics for you, it doesn't matter if it makes it easier for anyone to read. If it works as intended, why not?" So going off of that idea, why don't we all name all of our variables single letters? Yeah that sounds like a good idea doesn't? You know, as long as it works as intended.
Rather than saying that it will reach infinity faster, just say that the first iteration of the loop is run faster. It's less than 1/100th faster. It's a difference that should be neglected. |
|
|
| Report Abuse |
|
|
IcyFires
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 5046 |
|
|
| 08 Oct 2014 03:42 PM |
| Why should it be neglected, because it goes against what you are saying? And your 1 letter variable idea? There is only 26 letters. That is a problem. But applying the repeat loop in the situation I am presenting presents no such thing. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 08 Oct 2014 03:46 PM |
| The only thing wrong with using one letter variables is because they are only 26 letters? Okay, so I'm guessing your fairly inexperienced. There are plenty of times when you should do things one way over another, even though one way might be slightly quicker, or require slightly less memory, you still use the other way if it's more readable. That's good programming. |
|
|
| Report Abuse |
|
|
kubuto2
|
  |
| Joined: 16 Jul 2008 |
| Total Posts: 1275 |
|
|
| 08 Oct 2014 03:46 PM |
| All loops have its purpose. If you aren't using the conditional statement properly, and putting a wait() in there then you are not coding correctly. Putting a wait() as the conditional parts annoys me and others. |
|
|
| Report Abuse |
|
|
IcyFires
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 5046 |
|
|
| 08 Oct 2014 03:48 PM |
| I would never use 1 letter variables, but I wouldn't bash anyone for doing such. And I have been a Lua programmer for a good 2 years now. |
|
|
| Report Abuse |
|
|
IcyFires
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 5046 |
|
|
| 08 Oct 2014 03:49 PM |
@kub
It is not improper to say
while wait() do end
wait() is a condition that always returns true. I have no idea why you would have a problem with using that. |
|
|
| Report Abuse |
|
|
kubuto2
|
  |
| Joined: 16 Jul 2008 |
| Total Posts: 1275 |
|
|
| 08 Oct 2014 03:52 PM |
If you haven't noticed yet, go to notepad and write a lua script and try to use "wait()", it will cause an error.
+ In between while and do is suppose to be a condition.
Just trying to help you code better, don't take it offensive. |
|
|
| Report Abuse |
|
|
IcyFires
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 5046 |
|
|
| 08 Oct 2014 03:54 PM |
| Guess what, this is roblox lua, not standard lua. From what I know wait() is a roblox specific function. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 08 Oct 2014 03:54 PM |
Using wait() as a condition is weird to do, even if it returns true. If you were fluent in other languages you'd probably understand why. A non-ROBLOX programmer wouldn't think to see wait() as true.
Now, "I wouldn't bash anyone for doing such." You should because that is an awful programming habit. Not bash them of course, but correct them. |
|
|
| Report Abuse |
|
|
IcyFires
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 5046 |
|
|
| 08 Oct 2014 03:56 PM |
| If you can't see wait() as true, maybe you need to code in rbx.lua more. It is clear that wait returns a string, which is always true. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 08 Oct 2014 03:57 PM |
wait() returns a boolean that is true...
Now, the reason why you wouldn't do that is because you want your code to be readable by programmers of other common languages. |
|
|
| Report Abuse |
|
|
kubuto2
|
  |
| Joined: 16 Jul 2008 |
| Total Posts: 1275 |
|
|
| 08 Oct 2014 03:57 PM |
This what most of us see.
if wait() then end
Look how redundant that is. |
|
|
| Report Abuse |
|
|
IcyFires
|
  |
| Joined: 29 Jun 2013 |
| Total Posts: 5046 |
|
|
| 08 Oct 2014 03:59 PM |
| Wait actually returns a string, not a bool. But a string, and all other things beside false and nil are considered true. |
|
|
| Report Abuse |
|
|
lordrambo
|
  |
| Joined: 16 Jun 2009 |
| Total Posts: 20628 |
|
|
| 08 Oct 2014 04:00 PM |
Okay, you're right on the last bit there, but it returns a number
print(type(wait())) >number |
|
|
| Report Abuse |
|
|