A Roblox Community
Would you like to react to this message? Create an account in a few clicks or log in to continue.

A Roblox Community

A community of Robloxians who want to learn to script and build on Roblox Studio.
 
HomeLatest imagesRegisterLog in
If you're a experienced coder make some tutorials! It would really help the site grow.
Make sure you read the rules(Which can be found by clicking here)
If you're a beginner at coding, try some tutorials.
We have many Moderators/Admins watching this site. Contact them with Questions.
Let us know what your favorite sport is. By clicking here to vote (Click here)
This site is becoming inactive. Lets make it active.
Log in
Username:
Password:
Log in automatically: 
:: I forgot my password
Top posters
blueymaddog
Loops, loops, loops.... Vote_lcapLoops, loops, loops.... Voting_barLoops, loops, loops.... Vote_rcap 
naknak
Loops, loops, loops.... Vote_lcapLoops, loops, loops.... Voting_barLoops, loops, loops.... Vote_rcap 
Supernapalm
Loops, loops, loops.... Vote_lcapLoops, loops, loops.... Voting_barLoops, loops, loops.... Vote_rcap 
m27frogy
Loops, loops, loops.... Vote_lcapLoops, loops, loops.... Voting_barLoops, loops, loops.... Vote_rcap 
slayer9365
Loops, loops, loops.... Vote_lcapLoops, loops, loops.... Voting_barLoops, loops, loops.... Vote_rcap 
myrco919
Loops, loops, loops.... Vote_lcapLoops, loops, loops.... Voting_barLoops, loops, loops.... Vote_rcap 
branefreez
Loops, loops, loops.... Vote_lcapLoops, loops, loops.... Voting_barLoops, loops, loops.... Vote_rcap 
ninga95
Loops, loops, loops.... Vote_lcapLoops, loops, loops.... Voting_barLoops, loops, loops.... Vote_rcap 
CloneTrooper787
Loops, loops, loops.... Vote_lcapLoops, loops, loops.... Voting_barLoops, loops, loops.... Vote_rcap 
raboy117
Loops, loops, loops.... Vote_lcapLoops, loops, loops.... Voting_barLoops, loops, loops.... Vote_rcap 
Top posting users this month
No user
Latest topics
» Where to go from here.
Loops, loops, loops.... EmptySeptember 14th 2020, 1:20 pm by MrNicNac

» Send me an Email
Loops, loops, loops.... EmptySeptember 14th 2020, 1:16 pm by MrNicNac

» [v1.6.0.0] Lua Script Obfuscator [No Bytecode]
Loops, loops, loops.... EmptyJuly 6th 2015, 7:38 pm by m27frogy

» New Site Possibly
Loops, loops, loops.... EmptyJuly 6th 2015, 4:16 pm by m27frogy

» Ambassador!
Loops, loops, loops.... EmptyApril 15th 2015, 11:40 pm by naknak

» Boop - Tag
Loops, loops, loops.... EmptyApril 13th 2015, 9:46 pm by naknak

» Vip Class Script
Loops, loops, loops.... EmptyApril 13th 2015, 4:54 pm by naknak

» Who's active?!
Loops, loops, loops.... EmptyApril 13th 2015, 4:52 pm by naknak

» Genesis Point
Loops, loops, loops.... EmptyJuly 17th 2014, 7:04 pm by branefreez

» Reward System
Loops, loops, loops.... EmptyJuly 17th 2014, 5:41 am by m27frogy

» Script Request
Loops, loops, loops.... EmptyJuly 10th 2014, 11:43 am by naknak

» local scripts?
Loops, loops, loops.... EmptyJuly 10th 2014, 11:39 am by naknak

» Project: Reconstruction [Died]
Loops, loops, loops.... EmptyJuly 10th 2014, 11:36 am by naknak

» Hi. I am new here
Loops, loops, loops.... EmptyApril 26th 2014, 4:01 pm by altshiftkey

» What's your favorite sport?
Loops, loops, loops.... EmptyJanuary 1st 2014, 2:13 pm by m27frogy

» FlashLight Script
Loops, loops, loops.... EmptyJanuary 1st 2014, 2:11 pm by m27frogy

» Gun Making! [READ DESC]
Loops, loops, loops.... EmptyJanuary 1st 2014, 2:10 pm by m27frogy

» Hi, I am new here!
Loops, loops, loops.... EmptyNovember 26th 2013, 3:33 pm by Keanu73

» Improve Coding
Loops, loops, loops.... EmptyOctober 26th 2013, 1:12 pm by pook03

» Simple Button
Loops, loops, loops.... EmptySeptember 1st 2013, 6:19 pm by branefreez


 

 Loops, loops, loops....

Go down 
+2
raboy117
naknak
6 posters
AuthorMessage
naknak
Administrator
Administrator
naknak


Posts : 878
Join date : 2010-07-30

Loops, loops, loops.... Empty
PostSubject: Loops, loops, loops....   Loops, loops, loops.... EmptyJanuary 21st 2011, 9:32 pm

In this I will show you examples of all the kinds of loops RBX.lua has to offer.

While-do

While-do, more commonly known as while true do, is one of the most used loops. The reason being is that most scripters on Roblox only know about it, no other loops. The way to use this loop is to put something in between while and do. If whatever is in between the two is true, then it will continue. You must end the loop with an 'end'

Code:
while true do
wait()
print("Hello World")
end

Repeat-until

Repeat-until is another loop in RBX.lua. It repeats itself until its requirement is fulfilled.

Code:
repeat wait() print("Hello World") until 1 ~= 1

for-do

I use this to repeat something a specific amount of times, like if I wanted to make a script that counted down until it printed 'hi'

Code:
for i = 10,1,-1 do
print(i.. " second(s) until I print hi")
wait(1)
end
print("hi")

pairs loop

One of the more complex loops. This is used to run through an array and interact with its contents. 'i' is the number the script is on, 'v' is the object itself:

Code:
m = {"cookie","Milk","Cake")
for i,v in pairs(m) do
if v == "cookie" then
print("I ate my " ..v)
end
end


Last edited by naknak on March 5th 2011, 8:58 pm; edited 1 time in total
Back to top Go down
raboy117
Novice Scripter
Novice Scripter
raboy117


Posts : 75
Join date : 2011-01-19
Age : 27
Location : Canada, PEI, Charlottetown

Loops, loops, loops.... Empty
PostSubject: Re: Loops, loops, loops....   Loops, loops, loops.... EmptyJanuary 21st 2011, 9:34 pm

The only code i get is while true do i dont quite get 'for i = 10,1,-1 do
print(i.. " second(s) until I print hi")
wait(1)
end
print("hi")'


Back to top Go down
blueymaddog
Administrator
Administrator
blueymaddog


Posts : 1081
Join date : 2010-12-09
Age : 26

Loops, loops, loops.... Empty
PostSubject: Re: Loops, loops, loops....   Loops, loops, loops.... EmptyJanuary 26th 2011, 9:17 am

you should change While-do to while loops and For-do for loops. pairs is just a method of indexing through tables. watch me put caps in certain words of this line using pairs:

FOR i,v in pairs(table) DO

notice how it's still a for loop. 0.o
Back to top Go down
ninga95
Administrator
Administrator
ninga95


Posts : 122
Join date : 2010-07-30
Age : 29

Loops, loops, loops.... Empty
PostSubject: Re: Loops, loops, loops....   Loops, loops, loops.... EmptyFebruary 7th 2011, 5:18 pm

To make the for do loop easier to understand you would say

For loop makes a command or commands go a set of number of times

better example

Code:
L = 10
for i = 1, L do
print("Hey")
end
end


Last edited by ninga95 on February 9th 2011, 9:07 pm; edited 3 times in total
Back to top Go down
ninga95
Administrator
Administrator
ninga95


Posts : 122
Join date : 2010-07-30
Age : 29

Loops, loops, loops.... Empty
PostSubject: Re: Loops, loops, loops....   Loops, loops, loops.... EmptyFebruary 7th 2011, 5:21 pm

Also naknak i and v are just vairable names you can set different variables to it as long as the code is defined correctly.

Back to top Go down
slayer9365
Expert Scripter
Expert Scripter
slayer9365


Posts : 233
Join date : 2010-07-31
Age : 29

Loops, loops, loops.... Empty
PostSubject: Re: Loops, loops, loops....   Loops, loops, loops.... EmptyFebruary 7th 2011, 6:39 pm

I think that the pairs loops is really a for loop.
Back to top Go down
naknak
Administrator
Administrator
naknak


Posts : 878
Join date : 2010-07-30

Loops, loops, loops.... Empty
PostSubject: Re: Loops, loops, loops....   Loops, loops, loops.... EmptyFebruary 7th 2011, 7:27 pm

I never said anything about i and v not being changeable. Pairs is really a for loop, but it is best to understand them separately.
Back to top Go down
slayer9365
Expert Scripter
Expert Scripter
slayer9365


Posts : 233
Join date : 2010-07-31
Age : 29

Loops, loops, loops.... Empty
PostSubject: Re: Loops, loops, loops....   Loops, loops, loops.... EmptyFebruary 7th 2011, 9:27 pm

Just thought I would point out some technical stuff.
Back to top Go down
naknak
Administrator
Administrator
naknak


Posts : 878
Join date : 2010-07-30

Loops, loops, loops.... Empty
PostSubject: Re: Loops, loops, loops....   Loops, loops, loops.... EmptyFebruary 7th 2011, 10:19 pm

Fair enough.
Back to top Go down
slayer9365
Expert Scripter
Expert Scripter
slayer9365


Posts : 233
Join date : 2010-07-31
Age : 29

Loops, loops, loops.... Empty
PostSubject: Re: Loops, loops, loops....   Loops, loops, loops.... EmptyFebruary 7th 2011, 11:14 pm

I think that you may want to add that you need a minimum of wait() in the while loops.
Back to top Go down
myrco919
Intermediate Scripter
Intermediate Scripter
myrco919


Posts : 190
Join date : 2011-01-21
Age : 26
Location : Holland

Loops, loops, loops.... Empty
PostSubject: Re: Loops, loops, loops....   Loops, loops, loops.... EmptyMarch 5th 2011, 6:40 pm

"if v.Name == "cookie" then"

you mean

if v == "cookie" then
Back to top Go down
naknak
Administrator
Administrator
naknak


Posts : 878
Join date : 2010-07-30

Loops, loops, loops.... Empty
PostSubject: Re: Loops, loops, loops....   Loops, loops, loops.... EmptyMarch 5th 2011, 8:57 pm

Whoops. Yes.
Back to top Go down
blueymaddog
Administrator
Administrator
blueymaddog


Posts : 1081
Join date : 2010-12-09
Age : 26

Loops, loops, loops.... Empty
PostSubject: Re: Loops, loops, loops....   Loops, loops, loops.... EmptyNovember 20th 2011, 6:36 am

slayer9365 wrote:
I think that the pairs loops is really a for loop.

repeating what I said, much?
O_o
Back to top Go down
Sponsored content





Loops, loops, loops.... Empty
PostSubject: Re: Loops, loops, loops....   Loops, loops, loops.... Empty

Back to top Go down
 
Loops, loops, loops....
Back to top 
Page 1 of 1
 Similar topics
-
» Tutorial on: 'for' loops
» Time changing script - Loops forever

Permissions in this forum:You cannot reply to topics in this forum
A Roblox Community :: Tutorials and Resources :: Beginner-
Jump to: