Skip to main content
Announcements
See what Drew Clarke has to say about the Qlik Talend Cloud launch! READ THE BLOG
cancel
Showing results for 
Search instead for 
Did you mean: 
Anonymous
Not applicable

Do While ...Loop continued working after the condition became invalid

Hello!

I write some code as

set FirstYear=2016;

Let CurrentYear = Year(Today()); //2018

......

DO while $(FirstYear)  <= $(CurrentYear)

             $(vTable)__c_Final:

                              SQL SELECT  *

                               FROM

                               $(vTable)  Where CreatedDate>= $(FirstYear)-01-01T00:00:00.000+0000 and CreatedDate<= $(FirstYear)-12-31T00:00:00.000+0000;

                                 Let  FirstYear = $(FirstYear)+1;

                                 DROP $(vTable)_Final

                                  SLEEP 1000;

LOOP

....

This code started working and continued working after the condition became invalid! It works with FirstYear = 2016 (true), 2017 (true), 2018(true), 2019 ( false!!) and so on. And when I debug it I don't see "Do.." string in debug cycle. When I write condition in 'LOOP' string, cycle works true:

DO...

LOOP  while $(FirstYear)  <= $(CurrentYear)

works true.

Could you please tell me why cycle does not   work in first case?

1 Solution

Accepted Solutions
rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You should not use $() around FirstYear in the Do condition:

DO while FirstYear  <= $(CurrentYear)


-Rob

http://masterssummit.com

http://qlikviewcookbook.com

View solution in original post

7 Replies
Digvijay_Singh

not sure but I think you don't need to use 'Let' in below statement as the variable is already defined at the top, looks like its kind of creating FirstYear newly inside the loop -

  Let  FirstYear = $(FirstYear)+1; change this to


FirstYear = $(FirstYear)+1;



rwunderlich
Partner Ambassador/MVP
Partner Ambassador/MVP

You should not use $() around FirstYear in the Do condition:

DO while FirstYear  <= $(CurrentYear)


-Rob

http://masterssummit.com

http://qlikviewcookbook.com

Anonymous
Not applicable
Author

No, I used this code


FirstYear = $(FirstYear)+1; 


and had same result.

Anonymous
Not applicable
Author

No, you code don't work too

Anonymous
Not applicable
Author

Sorry!!!!! I hurried.

You where right!

onmysi49
Contributor III
Contributor III

Hello Rob,

I have a question regarding this very old post.

Today I also found out that using dollar sign expansion does not work in certain cases. See my case below:

Do while ($(#vRefDate) <= $(#vEndDate))
.
.
.
Let vRefDate = AddMonths($(#vRefDate),+1);
Loop

This does not work. I have to either move the condition to the end of the loop like this:

Do
.
.
.
Let vRefDate = AddMonths($(#vRefDate),+1);
Loop while ($(#vRefDate) <= $(#vEndDate))

Or I have to remove the dollar sign expansion from vRefDate variable in the condition like this:

Do while ((vRefDate) <= $(#vEndDate))
.
.
.
Let vRefDate = AddMonths($(#vRefDate),+1);
Loop


But my question is why? What is the cause that the Loop while works with dollar sign exp. and Do while does not? From time to time I am confused by behaviour of dollar sign expansion, which is quite tricky to understand in different use cases.

I only found this https://support.qlik.com/articles/000073866 article but that does not give me the explanation.

Thanks a lot. Have a great day.

Marius_
Contributor III
Contributor III

I had the same problem and removed the $() from the second condition as well, like:

 do while $(vInRes) < $(vUitRes)

->  do while vInRes < vUitRes

and it worked