# How to get the current number of iterations

Nicholasfox shared this question 2 years ago
Answered

I'm trying to complete a permutation using the iteration command.

In the expression below, "n" with underlined should be the number of iterations, but how can I get the current number of iterations?

Iteration(Join(Zip(Sequence(Insert(n, q, m), m, 1, n), q, p)), p, {{{1}}}, n)

Thanks.

Best Answer

Afaik there is no way to access the current number of iterations directly.

In your case it's not really necessary though, because n is always the length of q, so you could just replace "n" by "length(q)". Although I guess that you rather want to replace it by "length(q)+1", assuming that you are trying to generate permutations. (And you could even start with "{{}}" instead of "{{1}}" so that n matches the length of the permutations.)

`Iteration(Join(Zip(Sequence(Insert(Length(q) + 1, q, m), m, 1, Length(q) + 1), q, p)), p, {{{}}}, n)`

A general workaround is to keep track of the current iteration by making it part of the list that is iterated over. It's always a bit annoying to write though and makes the Iteration command line even less readable.

## Comments (2)

2

Afaik there is no way to access the current number of iterations directly.

In your case it's not really necessary though, because n is always the length of q, so you could just replace "n" by "length(q)". Although I guess that you rather want to replace it by "length(q)+1", assuming that you are trying to generate permutations. (And you could even start with "{{}}" instead of "{{1}}" so that n matches the length of the permutations.)

`Iteration(Join(Zip(Sequence(Insert(Length(q) + 1, q, m), m, 1, Length(q) + 1), q, p)), p, {{{}}}, n)`

A general workaround is to keep track of the current iteration by making it part of the list that is iterated over. It's always a bit annoying to write though and makes the Iteration command line even less readable.

1

Got it. length(q)+1 is a great idea. Thank you very much.

Leave a Comment
• GeoGebra
• Help
• Partners
• Contact us
• Feedback & Questions
• This email address is being protected from spambots. You need JavaScript enabled to view it.
• +43 677 6137 2693
© 2023 International GeoGebra Institute