Question: Why does no output appear when i have a nested conditional?

Ok, I've got a matrix where the elements are lists of length 3, the first element tells you what sort of entry it is; the important thing to know here is that if the first entry is one then the second entry (and third) is a variable.

I want to construct a set containing only the variables (i.e. no scalars from the matrix or anything like that), not the other 'second entries' of other elements in the matrix. It should work if you copy and paste the maple code below, maybe someone could tell me where I'm going wrong.
The strange thing is, it works if I leave out the 'while' argument in the for...do...end do command, but then of course it gives me unwanted elements in my final set. I've tried using a nested if...then command but it has the same effect (which is that the output just disappears/doesn't exist). I've noticed before as well that whenever I do something nested it does this, for instance if i want to do something like

for i from 1 to 3 do
 for j from 1 to 3 do...

then it similarly can't give an output. Is there something obvioius that I'm missing?

Anyway, here's the maple code.

p.s. I know there aren't very many elements so I could do it by hand but I'm planning on applying a very similar thing to bigger Matrices when I can get this to work.

M := Matrix(3, 3, {(1, 1) = [0, 0, 0], (1, 2) = [2, 4, 0], (1, 3) = [2, 3, 0], (2, 1) = [2, 0, 3], (2, 2) = [1, x[12], x[12]], (2, 3) = [1, x[20], x[20]], (3, 1) = [2, 0, 4], (3, 2) = [1, x[24], x[24]], (3, 3) = [1, x[40], x[40]]}):

vars:={}:


#Here I am trying to get the variables x[i] out of the matrix, by using the fact that if the first element in the list of an entry in the matrix is 1, then the second element is a variable.
for i from 1 to 3 while op(1,M[i,2])=1 do
 vars:=vars union {op(2,M[i,2])}
end do;


p
please help, thanks very much! (i can't seem to get rid of that
' align='absmiddle'> thing, that's not part of my code!)

Please Wait...