• Want to help us with this year's BoS Trials?
    Let us know before 30 June. See this thread for details
  • Looking for HSC notes and resources?
    Check out our Notes & Resources page

For Loop (1 Viewer)

MrTanman

Fascist
Joined
Feb 4, 2009
Messages
54
Location
Cabra
Gender
Male
HSC
2011
Uni Grad
2014
May someone please interpret this For Loop script for me?
I want to know how t equals 20.

Code:
t = 0;
for (i = 1 to 3) {
             for (j = 0 to i) {
                      t = t + i;
                      next j;
             }
             next i;
}
display t;
Thanks
 

alcalder

Just ask for help
Joined
Jun 26, 2006
Messages
601
Location
Sydney
Gender
Female
HSC
N/A
t = 0
i = 1
j = 0 , t = 1
j = 1, t = 2
i = 2
j = 0, t = 4
j = 1, t = 6
j = 2, t = 8
i = 3
j = 0, t = 11
j = 1, t = 14
j = 2, t = 17
j = 3, t = 20

Remember, t = t + i not t = t+1
 
Last edited:

Users Who Are Viewing This Thread (Users: 0, Guests: 1)

Top