Which is more performant?
function MovementSystem:Run(ClientTable, deltaTime)
while self.sprintAction do
--stuff
end
if self.sprintAction then
-stuff
end
end
Which is more performant?
function MovementSystem:Run(ClientTable, deltaTime)
while self.sprintAction do
--stuff
end
if self.sprintAction then
-stuff
end
end
Is this a joke? They’re completely different
not in my case lol. I was guessing someone would ask
I mean this fully depends on how your system works? As previously said they are completely different.
While loops until the result ends in false or nil so they are less optimized yeah, but this should really depend on what you are trying to achieve and if you even need it to loop or not.
If you only need it to run once please do if then statements
They are exactly the same for the compiler; the only difference is that in a while loop, if the if statement is true, then it jumps back to the start and executes code over and over again until the statement breaks.
Same with repeat until but in reverse - same compiled result with no difference.
I assume you expect if-then functionality.
Both work equally if false == self.sprintAction.
If true == self.sprintAction then while loop never ends.
Unless you decide to update self.sprintAction to false in the while loop to break it.
But that’s: additional check that breaks the loop and additional code that updates self.sprintAction in the loop body.
So seems that if-then is more optimized.
Absolutely untrue.
It produces an entirely different set of instructions that is MUCH MUCH slower than checking if a value is truthy or not.
if a then end
![]()
if a==true then end
![]()
This topic was automatically closed 14 days after the last reply. New replies are no longer allowed.