How do i run a loop INSTANTLY? (read desc)

so basically i want to run a loop instantly over and over.
For example:
A While loop needs a task.wait, and even with the smallest amount of time put in it the loop still takes a few milliseconds to continue onto the next loop

But For loops do it instantly, it doesnt need a wait either.

Is there a normal loop i can make that runs for a specifided amount of loops like 100 times or 1000 times and does not wait at all?
The reason im trying to do this is because i need my game to make thousands of small calculations within the smallest amount of time possible, and while loops just arent fast enough

2 Likes

4 Likes

yeah thats why im asking if a loop exists that works like a for loop but “loops” like a while loop AKA loops instantly with no wait time

dude that’s not possible at all, a while loop will happen as long as a condition is true so if you don’t have a yield it’s running too fast and you’ll get the error I showed up there, a for loop on the other hand has an end so you don’t need to yield although for more computational expensive stuff it’ll have to work harder

my only guess is doing something like this

local Time = 0 

while true do 
    Time += 1
    
    --// do stuff 

    if (Time%250==0) then 
        task.wait() 
    end
end



He’s saying not yield at all so that means no sort of function that will yield the next iteration

Which simply isnt possible for while loops

1 Like

the calculation are jusr like adding things, checking conditions, and setting conditions… im not trying to get it to run an ai or something

But why exactly do you need it to run instantly though?

ik its not possible with while loops, but it is possible with for loops so im wondering if theres an in-between

because the whole while loop wating thing belive it or not takes too long for how fast i have to do all of this

bro are you like doing calculations for the next moon landing, why do your calculations have to be calculated so fast

1 Like

the calculations are for a few additions subtraction checks and settings, nothing too complicated

Are you making a world generator…?


local iter = 0
while iter < 1000 do
   --...
   iter += 1
end

Does this fit your need?

How is it not possible with while loops but possible with for lops? To make the while loop not yield, just don’t put a task.wait in the body or condition.

All you have to do with the while loop to avoid an execution timeout is put an exit condition somewhere.

1 Like

if you really want me to explain what im doing i can but its a lot to explain

the fastest thing like it is runservice.heartbeat to my wonderful knowledge

dude a while loop runs forever as long as a condition is true, it’ll literally throw a script timeout

so does anyone have a solution yet?

i literally told you countless times that it isnt possible to not yield a while loop

Not until you explain what you’re trying to do.
https://xyproblem.info/

1 Like