8 Replies Latest reply: Mar 16, 2012 5:59 AM by cclcjr14 RSS

    how to jump into next in a FOR loop

      For i=1 to 3

           if $(i)<2 then

                //jump to next

           end if;

           //code xxxxxxx

           //code yyyyyyyy



      Above is the requirement, if i=1, do nothing.

      I know I can put the code xxxx/yyyyy into ELSE, any other workaround/solution?


      How to do this? I tried NEXT, but I get runtime error.

        • how to jump into next in a FOR loop
          j i

          Just do the loop from 2 to 3


          Fori = 2 to 3

          code xxxxx

          code yyyy


          • how to jump into next in a FOR loop
            Christophe Brault



            Can you take the problem by the other side like :


            For i=1 to 3

                 if $(i)>2 then

            //code xxxxxxx

                 //code yyyyyyyy

                 end if;

                 // do nothing



            Don't know if this can help you.


            In the FOR NEXT loop, you can use the Key Word EXIT with a condition. See QlikView Manual in Script in Key Words for more information on how to use this.

              • how to jump into next in a FOR loop

                hi Chris,


                thx, I know 'exit for unless xxxx' syntax, thank you all the same.


                Hi qlikuser14,


                Okay I didn't clearly explain what I need.

                The 1,3, 2 are both hard coded here, for easily read code. Actually they will both be variables, $(a), $(b), etc.


                The requirement is that: I need to read the status of rows one by one, if fit some condition, then execute the rest command, otherwise, jump to next row.

                For example, if age <20 and salary >10000, then update the status as "good boy", otherwise, do nothing.

                So maybe row 1st, 4th & 5th are "good boy", but 2nd, 3rd & 6th are not.

                Is that clear?

                  • how to jump into next in a FOR loop
                    j i

                    Ok, well I'mnot sure how your structure is, but you could do this



                    LOAD * INLINE [

                        age, salary

                        19, 1001

                        20, 1000





                    age, salary,

                    if(age<20 and salary >1000, 'Good boy')

                    Resident b;

                    drop table b;

                      • how to jump into next in a FOR loop

                        Okay I understand what you said. But that's not what I want.


                        As I said, the condition is dynamic.

                        For 1st row, age condition might be >20, for 2nd, age might be >40.

                        And also for salary.

                        Catch what I say?


                        So, it will take more effort to use WHERE condition to filter the uesful data. Of course I can do that, but it will be more complex.


                        That's the reason why I ask this question. I want to find a easy way to implement this. Right now I have already find out 3 workaround, I just want to research if there has any better solution.