Scripting HelpersARCHIVE
A little piece of Roblox history. Preserved for everyone, one question at a time.Read about the archive →
✓ ANSWER ACCEPTED

Question about while loops?

	while i < 5 do
		wait(0.5)
		boot_text.Text = boot_text.Text .. " ."
		i = i + 1 
		if i == 5 then
			i = 1 
			boot_text.Text = "Booting"
		end
	end

I want this loop to stop after 3 cycles (meaning that once i has been reset to = 1, three times).

Is this possible?

1 comment

0

do you just want it to run 3 times?

2 answers

✓ Accepted answer

You can use a nested for loop to achieve this. Essentially, we have a crown loop call a second loop #n time(s). You can also achieve better efficiency with this iteration function as it allows us to provide a numerical condition start, stop, step (optional) which get's pushed into a parameter that we can use to keep track of our current iteration in the same behavior as creating a variable and incrementing it.


####Note:

You can use the :rep() method of String to determine how many trailing dot characters you wish to append to the text without having to add it piece by piece.


for _ = 1,3 do
	for i = 0,5 do
		boot_text.Text = "Booting"..('.'):rep(i)
	wait(.5) end
end

1 comment

0

Thank you!

Yes this is possible. Maybe the simplest way would be to add a cycle variable to count how many times the loop runs. I will insert this variable into your code. Actually let me adjust the code a little bit more.

local cycleCount = 0
while cycleCount < 3 do
    cycleCount = cycleCount + 1
    for i = 1, 5 do
        wait(0.5)
        boot_text.Text = boot_text.Text .. " ."
        i = i + 1 
        if i == 5 then
            i = 1 
            boot_text.Text = "Booting"
        end
    end
end

This should just count each time the while loop runs and stop when cycleCount gets to 3. It should also run the loop to get i to 5 and run the code for that as well. Hopefully this helped!

4 comments

0

I just updated the answer given. Hopefully this is what you wanted it to do, I have not tested it but it should give you an idea.

0

Use a nested for loop.

0

You could also use a nested for loop yes.

0

Thank you!

This discussion is preserved as it was. New answers, comments, and votes are closed.