Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

olegsavinkov
New Contributor

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

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

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

DO while FirstYear  <= $(CurrentYear)


-Rob

http://masterssummit.com

http://qlikviewcookbook.com

5 Replies
Digvijay_Singh
Honored Contributor III

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

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;



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

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

DO while FirstYear  <= $(CurrentYear)


-Rob

http://masterssummit.com

http://qlikviewcookbook.com

olegsavinkov
New Contributor

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

No, I used this code


FirstYear = $(FirstYear)+1; 


and had same result.

olegsavinkov
New Contributor

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

No, you code don't work too

olegsavinkov
New Contributor

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

Sorry!!!!! I hurried.

You where right!

Community Browser