Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Not applicable

Endless do loop: "do while ($(a) <= 3) "

Hi,

can anyone explain me what happens when I use "do while ($(a) <= 3) " ?

When i use "do while ($(a) <= 3)" I get an endless loop.

With "do while (a <= 3) " it works right.

What´s the difference?

Example see below.

Table:
LOAD * INLINE [
Test1, Test2
1, 88
2, 77
3, 66
4, 55
9, 99
];

LET a = 1;
do while ($(a) <= 3)
LOAD
Test1,
Test2 AS NTEST2
RESIDENT Table;
LET a = a + 1;
loop

Thanks

1 Solution

Accepted Solutions
pat_agen
Specialist
Specialist

hi,

the help function says the following about the do .. loop

"each condition is interpreted only the first time it is encountered but it is evaluated for every time time it [is] encountered in the loop."

You have used the $() expansion so that when the script encounters this line it interpretes it as

"do while(1<=3)"

it will then evaluate this same line again and again, hence your endless loop.

When you don't use $() expansions the script interpretes

"do wile (a<=3)"

this is succesfully evaluated at each loop.

I think that explains what you are seeing - use the debug fucbntion in the script editor to get a close look at what is happening as your script is stepped through.

View solution in original post

1 Reply
pat_agen
Specialist
Specialist

hi,

the help function says the following about the do .. loop

"each condition is interpreted only the first time it is encountered but it is evaluated for every time time it [is] encountered in the loop."

You have used the $() expansion so that when the script encounters this line it interpretes it as

"do while(1<=3)"

it will then evaluate this same line again and again, hence your endless loop.

When you don't use $() expansions the script interpretes

"do wile (a<=3)"

this is succesfully evaluated at each loop.

I think that explains what you are seeing - use the debug fucbntion in the script editor to get a close look at what is happening as your script is stepped through.