Qlik Community

QlikView App Development

Discussion Board for collaboration related to QlikView App Development.

Announcements
QlikWorld 2020: Join us May 11 - 14, 2020 in Phoenix, AZ. Register early and save $400. Learn More
Highlighted
Not applicable

Let scope

I have a loop in my script, something like below:

For i = 0 TO 10

    LET expr = i * 2;

NEXT i

I would like to know whether expr variable created within loop is available outside loop for, for example, could I do something like below?

or I need to declare variable expr before loop for using SET sentence?

For i = 0 TO 10

    LET expr = i * 2;

NEXT i

LET another_expr = expr;  // What is the value for expr here? 20?

Tags (3)
1 Solution

Accepted Solutions
Partner
Partner

Re: Let scope

Hi Tony TP,

variable expr is not private to the for loop.

That's why, you can perform transferring value of expr to another_expr.

which is 20 at the end of For Next.

Its interesting to run the loop in debug to follow the iterations.

regards,

jp

View solution in original post

5 Replies

Re: Let scope

Might be from 0 to 9 The values are not correct. That's why the loop working on 10th Value

10 * 2 = 20

Before develop something, think If placed (The Right information | To the right people | At the Right time | In the Right place | With the Right context)
Partner
Partner

Re: Let scope

Hi Tony TP,

variable expr is not private to the for loop.

That's why, you can perform transferring value of expr to another_expr.

which is 20 at the end of For Next.

Its interesting to run the loop in debug to follow the iterations.

regards,

jp

View solution in original post

Employee
Employee

Re: Let scope

Qlikview variables are always global scope.

in your case, last value for expr = 10 * 2 = 20

MVP
MVP

Re: Let scope

try this, I added some trace to your "for loop"

For i = 0 TO 10

    LET expr = i * 2;

    trace i=$(i) expr=$(expr);

NEXT i

LET another_expr = expr;  

trace another_expr=$(another_expr);

and you get this result

i=0 expr=0

i=1 expr=2

i=2 expr=4

i=3 expr=6

i=4 expr=8

i=5 expr=10

i=6 expr=12

i=7 expr=14

i=8 expr=16

i=9 expr=18

i=10 expr=20

another_expr=20

I would like to know whether expr variable created within loop is available outside loop for, for example, could I do something like below?

          yes

or I need to declare variable expr before loop for using SET sentence?

          no

LET another_expr = expr;  // What is the value for expr here? 20?

          yes

Not applicable

Re: Let scope

Thanks for your example and for your detailed explanation