The Student Room Group
Reply 1
The "FOR I = 1 TO 6" bit means you only apply the algorithm if I takes a value between 1 and 6 inclusive.

The algorithm's not well-written, but I think you should just start with I and J equal to 1, since this is logical. The algorithm should then output the squares of 1, 2, 3, 4 and 5. I don't think it'll output the square of 6 because the algorithm doesn't run when J > 5.
Reply 2
thanks, i thought it was going to be something really complicated.
Reply 3
coral_fangs
I've got a couple of questions like this. I think that it's upposed to be easy but there's a part to it that i just don't get. Here it is:
X=0, K=0
FOR I = 1 TO 6
FOR J = 1 TO 5
X = I x J
K = K + 1
PRINT K, I, "times", J, "equals", X
NEXT J
NEXT I
END

What is FOR I = 1 TO 6 and FOR J = 1 TO 5 all about? How do i know what I and J are? Will the rest make sense when i figure this out?
Thanks for any help.


This code fraction simply outputs some partial multiplication tables.
You have an outer loop and an inner loop.
The inner loop variable varies from 1 to 5 for each value taken by the outer loop variable.
When I =1, say, J takes the values from 1 to 5, and X takes the values,
X = I*J = 1*1
X = I*J = 1*2
X = I*J = 1*3
.....

And within the inner loop, you have a print statement that writes,

K, I, "times", J, "equals", X

puting in values for the outer loop variable I = 1, and K constantly incrementing,

1, 1 times 1 equals 1
2, 1 times 2 equals 2
3, 1 times 3 equals 3
4, 1 times 4 equals 4
5, 1 times 5 equals 5

There ends the first run of the innner loop. The outer loop now increments it's loop variable, I, to equal 2, and the inner loop now outputs a 2nd times table.

6, 2 times 1 equals 2
7, 2 times 2 equals 4
8, 2 times 3 equals 6
9, 2 times 4 equals 8
10, 2 times 5 equals 10

etc.

Latest