Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 
mmvs
Contributor II
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)
1 Solution

Accepted Solutions
vinieme12
Champion III
Champion III

as below

 

 

temp:
load * inline [
Dim,loop1,loop2
A,2,3
B,4,2
C,2,1
];

Main:
Load
Dim
,l1
,IterNo() as l2
,recno() as id
While IterNo() <=loop2
;
load 
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.

View solution in original post

4 Replies
QFabian
Specialist III
Specialist III

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

 

Aux:
Load * INLINE [
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');

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

 

 

Next

drop table Aux;

QFabian
vinieme12
Champion III
Champion III

as below

 

 

temp:
load * inline [
Dim,loop1,loop2
A,2,3
B,4,2
C,2,1
];

Main:
Load
Dim
,l1
,IterNo() as l2
,recno() as id
While IterNo() <=loop2
;
load 
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.
mmvs
Contributor II
Contributor II
Author

Thank you very much @vinieme12 !

This did the trick.

Works exactly as intended.

 

Regards, Matthijs

mmvs
Contributor II
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