djboy
|
  |
| Joined: 16 Mar 2008 |
| Total Posts: 794 |
|
|
| 27 Nov 2013 04:49 PM |
may some one please tell me what this means?
for i = 1,20 do BLAH BLAH BLAH end |
|
|
| Report Abuse |
|
|
|
| 27 Nov 2013 04:51 PM |
for i = 1,20 do -- run loop 20 times adding 1 to value( i ) each time. blahblahblah -- the code you want to run in the code it could be, print(i) -- show loop iteration (value of i) end -- ends looping code, |
|
|
| Report Abuse |
|
|
djboy
|
  |
| Joined: 16 Mar 2008 |
| Total Posts: 794 |
|
|
| 27 Nov 2013 04:53 PM |
| but whats the point of adding 1 to i then? |
|
|
| Report Abuse |
|
|
LV1Z
|
  |
| Joined: 23 Jul 2011 |
| Total Posts: 652 |
|
| |
|
|
| 27 Nov 2013 04:56 PM |
for codes like
for i = 1,0,-0.1 do -- go from 1 to 0 at 0.1 per loop brick.Transparency = i -- change to value of i wait(0.1) end
this would give a smooth transparency change instead of this.
brick.Transparency = 1 wait(0.1) brick.Transparency = 0.9 wait(0.1) etc... brick.Transparency = 0
|
|
|
| Report Abuse |
|
|
djboy
|
  |
| Joined: 16 Mar 2008 |
| Total Posts: 794 |
|
|
| 27 Nov 2013 04:56 PM |
so if i did i = 2,20 does that mean it will run the script 40 times? |
|
|
| Report Abuse |
|
|
|
| 27 Nov 2013 04:58 PM |
for i = s,e,i do
s = start number e = end number i = interval
total loops can be worked out as ((e-s)/i) |
|
|
| Report Abuse |
|
|
djboy
|
  |
| Joined: 16 Mar 2008 |
| Total Posts: 794 |
|
|
| 27 Nov 2013 05:00 PM |
| mind telling me in math terms?, Like S*S/I ??? |
|
|
| Report Abuse |
|
|
|
| 27 Nov 2013 05:00 PM |
((e-s+1)/i) sorry,
so if
s = 1 e = 10 i = 0.1
then
10 - 1 + 1 = 10 10/0.1 = 100
so the loop will run 100 times |
|
|
| Report Abuse |
|
|
djboy
|
  |
| Joined: 16 Mar 2008 |
| Total Posts: 794 |
|
|
| 27 Nov 2013 05:02 PM |
| But do i need to add a i interval in the equation? |
|
|
| Report Abuse |
|
|
|
| 27 Nov 2013 05:05 PM |
if you dont then it will default as 1
----------------------- for i = 1,10 do
is the same as
for i = 1,10,1 do |
|
|
| Report Abuse |
|
|
djboy
|
  |
| Joined: 16 Mar 2008 |
| Total Posts: 794 |
|
| |
|
|
| 27 Nov 2013 05:07 PM |
No.
for VAR = START, STOP, STEP do -- CODE end
This creates a variable VAR that holds (in this case) a number value. This number starts at the value of START. Then, the loop runs after checking if START is less than STOP (if START was lower) or greater than STOP (if START was higher). At the end of the loop, VAR is incremented by STEP, which has a default value of 1.
Sound confusing? Let's look at some examples.
for i = 1, 20 do print(i) end -- this prints numbers 1 to 20, increasing by 1 each time
for i = 10, 0, -1 do print(i) end -- this prints numbers 10 to 0, increasing by -1 each time
for i = 23, 24, 2 do print(i) end -- this prints number 23
Here's a basic look at that the for loop is like:
FOR(VAR, START, STOP, STEP, CODE) if STEP is not a number STEP = 1 end if if STEP < 0 while START < STOP execute CODE START = START + STEP end while elseif STEP > 0 while START > STOP execute CODE START = START + STEP end while end if end FOR
You'll notice the for loop is considered a PRE-TEST loop. This means the condition (START > STOP or START < STOP) is checked BEFORE the code is executed. You may also notice the code will not be executed if your STEP is 0. |
|
|
| Report Abuse |
|
|
|
| 27 Nov 2013 05:09 PM |
"This creates a variable VAR that holds (in this case) a number value. This number starts at the value of START. Then, the loop runs after checking if START is less than STOP (if START was lower) or greater than STOP (if START was higher). At the end of the loop, VAR is incremented by STEP, which has a default value of 1."
Correction:
This creates a variable VAR that holds (in this case) a number value. This number starts at the value of START. Then, the loop runs after checking if START is less than STOP (if STEP was negative) or greater than STOP (if STEP was positive). At the end of the loop, VAR is incremented by STEP, which has a default value of 1. |
|
|
| Report Abuse |
|
|
|
| 27 Nov 2013 05:12 PM |
all you did was add the fact that if endnumber is less that startnumber then step is default negative 1.
what i said was by no means wrong, |
|
|
| Report Abuse |
|
|
|
| 27 Nov 2013 05:13 PM |
"what i said was by no means wrong,"
That No wasn't to your post. XD I lateposted because I decided to write a novel about the for loop. It was a response to this post:
"so if i did i = 2,20 does that mean it will run the script 40 times?"
Apologies. Shoulda known you guys would have been posting while I spent my two hours writing that novel. XD |
|
|
| Report Abuse |
|
|
|
| 27 Nov 2013 05:14 PM |
ahh, it happens,
although, others would say you got ninja'd ;) |
|
|
| Report Abuse |
|
|
|
| 27 Nov 2013 05:19 PM |
I'll admit I'm not as fast as I once was .... Does that make me old? D: |
|
|
| Report Abuse |
|
|
| |
|
2DB
|
  |
| Joined: 18 Nov 2013 |
| Total Posts: 109 |
|
| |
|
cntkillme
|
  |
| Joined: 07 Apr 2008 |
| Total Posts: 44956 |
|
| |
|
| |
|