Qlik Community

QlikView Scripting

Discussion Board for collaboration on QlikView Scripting.

Not applicable

Nested Loops - How to enforce a Next?

Hi,

I'm using 2 nested loops.

In the inner loop, I'm using IF blocks.

I would like to define a condition which would force the Next of the inner loop.

Using the Exit would cause performing commands in vetween the loops,

which is not desired.
I bypass it by using flags.But I wish to know whether it is possible to define something like:

IF condition THEN

     NEXT

ENDIF

To this end, didn't find a similar syntax.

Thanks :-)

1 Solution

Accepted Solutions
MVP
MVP

Re: Nested Loops - How to enfirce a Next?

Hi,

Try this,  if you don't give next it will automatically goto next for because u r else below it.  Remove next.

FOR I = 1 to $(vDelivNoOfRows)

// Here come a few commands

  FOR j =   $(Counter)+1 to (vReceiveNoOfRows)

//--Some commands

IF vBalance < 0 then
LET VDelQty = fabs($(vBalance));

SET vNextDelDoc = 'F';
LET Counter = $(Counter) + 1;
ELSEIF   vBalance = 0 then
LET Counter = $(Counter) + 1;
SET vNextDelDoc = 'T';
ELSE                              
LET VRecvQty = vBalance;                   
SET vNextDelDoc = 'T';
EXIT For;
ENDIF;

NEXT;

NEXT;


Regards,

Jagards.

9 Replies
Highlighted

Re: Nested Loops - How to enfirce a Next?

can you load your script please?

Not applicable

Re: Nested Loops - How to enfirce a Next?

Hi Manish,

It looks something like that. The NEXT in red causes a script error:

FOR I = 1 to $(vDelivNoOfRows)

// Here come a few commands

  FOR j =   $(Counter)+1 to $(vReceiveNoOfRows)

//--Some commands

IF vBalance < 0 then
LET VDelQty = fabs($(vBalance));

SET vNextDelDoc = 'F';
LET Counter = $(Counter) + 1;
NEXT;                
ELSEIF   vBalance = 0 then
LET Counter = $(Counter) + 1;
SET vNextDelDoc = 'T';

ELSE
                             
LET VRecvQty = vBalance;                   
SET vNextDelDoc = 'T';
EXIT For;

ENDIF;


NEXT;

NEXT;

Thanks!

MVP
MVP

Re: Nested Loops - How to enfirce a Next?

May be this?



FOR I = 1 to $(vDelivNoOfRows)

// Here come a few commands

  FOR j =   $(Counter)+1 to $(vReceiveNoOfRows)

//--Some commands

IF vBalance < 0 then
LET VDelQty = fabs($(vBalance));

SET vNextDelDoc = 'F';
LET Counter = $(Counter) + 1;
NEXT;                
ELSEIF   vBalance = 0 then
LET Counter = $(Counter) + 1;
SET vNextDelDoc = 'T';

ELSE
                             
LET VRecvQty = vBalance;                   
SET vNextDelDoc = 'T';
EXIT For;

ENDIF;

END IF;


NEXT;

NEXT;

Not applicable

Re: Nested Loops - How to enforce a Next?

Hi,

Sometimes, you want to move directly to the next record in the inner loop,

bypassing a group of commends between the two NEXT commands.

If it is not enabled in QlikView, the only way to do it is by using EXIT FOR and flags.

Thanks!

MVP
MVP

Re: Nested Loops - How to enfirce a Next?

Hi,

Try this,  if you don't give next it will automatically goto next for because u r else below it.  Remove next.

FOR I = 1 to $(vDelivNoOfRows)

// Here come a few commands

  FOR j =   $(Counter)+1 to (vReceiveNoOfRows)

//--Some commands

IF vBalance < 0 then
LET VDelQty = fabs($(vBalance));

SET vNextDelDoc = 'F';
LET Counter = $(Counter) + 1;
ELSEIF   vBalance = 0 then
LET Counter = $(Counter) + 1;
SET vNextDelDoc = 'T';
ELSE                              
LET VRecvQty = vBalance;                   
SET vNextDelDoc = 'T';
EXIT For;
ENDIF;

NEXT;

NEXT;


Regards,

Jagards.

MVP
MVP

Re: Nested Loops - How to enforce a Next?

Do you have any syntactical example from any other language to understand it better? I guess what you want can be achieved using IF..Else properly. Like:

For a=1 to 10

If a<>2 then                 // for a=2, the loop would move to next

     ...all others IFs.

End If

Next a

MVP
MVP

Re: Nested Loops - How to enfirce a Next?

Hi,

Try Exit For When|Unless.

Regards,

Jagan.

Not applicable

Re: Nested Loops - How to enforce a Next?

Got It!

Thanks!

Not applicable

Re: Nested Loops - How to enforce a Next?

Well, I thought I recalled that it's possible in VB.

But It's not.

The right way to do it is like you and Jagan suggested.

Thanks!