Announcements
cancel
Showing results for
Did you mean:
Contributor II

## Nested while loop

Hello,

I've got a table with the following structure:

A   2   3

B   4   2

C   2   1

What I would like to do is first iterate over the 2nd column and produce an amount of rows equal to the number in that field. Then it needs to do the same for the field in the 3rd column. The result should be like this:

A   1   1

A   1   2

A   1   3

A   2   1

A   2   2

A   2   3

B   1   1

B   1   2

B   2   1

B   2   2

B   3   1   etc...

I can get either column 2 or column 3 working with IterNo() and While, but not both at the same time. Is there anyone who could help me solve this problem? Any help is much apreciated!

Regards, Matthijs

Labels (1)
• ### General Question

1 Solution

Accepted Solutions
Champion III

as below

``````temp:
Dim,loop1,loop2
A,2,3
B,4,2
C,2,1
];

Main:
Dim
,l1
,IterNo() as l2
,recno() as id
While IterNo() <=loop2
;
Dim
,loop2
,IterNo() as l1
resident temp
While IterNo() <=loop1
;
drop table temp;
exit script;``````

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
4 Replies
Specialist III

Hi @mmvs , fun one!, please check this script :

Aux:
F1, F2, F3
A, 2, 3
B, 4, 2
C, 2, 1
];

For vRow = 0 to NoOfRows('Aux') - 1
Let vF1 = peek('F1', vRow, 'Aux');
Let vF2 = peek('F2', vRow, 'Aux');
Let vF3 = peek('F3', vRow, 'Aux');

'\$(vF1)' as F1
Autogenerate(1);
join
rowno() as F2
Autogenerate(vF2);
join
rowno() as F3
Autogenerate(vF3);

Next

drop table Aux;

QFabian
Champion III

as below

``````temp:
Dim,loop1,loop2
A,2,3
B,4,2
C,2,1
];

Main:
Dim
,l1
,IterNo() as l2
,recno() as id
While IterNo() <=loop2
;
Dim
,loop2
,IterNo() as l1
resident temp
While IterNo() <=loop1
;
drop table temp;
exit script;``````

Vineeth Pujari
If a post helps to resolve your issue, please accept it as a Solution.
Contributor II
Author

Thank you very much @vinieme12 !

This did the trick.

Works exactly as intended.

Regards, Matthijs

Contributor II
Author

Thank you for your help @QFabian !

I got an error when loading the script: Autogenerate: generate count is out of range .

It happened with AutoGenerate(vF2) .

Regards, Matthijs