Unlock a world of possibilities! Login now and discover the exclusive benefits awaiting you.
For i=1 to 3
if $(i)<2 then
//jump to next
end if;
//code xxxxxxx
//code yyyyyyyy
NEXT
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.
Just do the loop from 2 to 3
Fori = 2 to 3
code xxxxx
code yyyy
NEXT
r u kidding me?
What I need is a keyword like CONTINUE in SQL server. I just want to know if QV has such key word or not.
Hi,
I didn't found such Keyword in Qlikview, so using ELSE is the best way.
Regards,
Jagan.
No, I'm not kidding. I'm just giving you an answer for a silly question you made. From what I see in your example , doing a for frmo 2 to 3 would make the trick.
If you are so smart, you could have gone to the Qlik HELP and see that there's no CONTINUE statement for the FOR...NEXT control statement.
Next time be more respectful with the people that is investing time to help you.
Hi,
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
NEXT
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.
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?
Ok, well I'mnot sure how your structure is, but you could do this
b:
LOAD * INLINE [
age, salary
19, 1001
20, 1000
];
load
age, salary,
if(age<20 and salary >1000, 'Good boy')
Resident b;
drop table b;
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.
Hi everyone,
I noticed this is an older post, but in case it helps others who stumble upon it, I'll share some solutions for looping:
1st of all, there is no "continue" keyword in Qlik (that I am aware of), but there are some ways to achieve the same thing
Considering the provided example (without specific error):
I'll make some assumptions and offer two approaches to exclude lines from your loop.
Tip 1: Meaningful Loop Variable Names
I recommend using descriptive loop variable names. For example, instead of i
, consider listIndex
or counter
. This improves code readability.
Tip 2: Specify Which Loop to Iterate
Especially with nested loops, clearly state which loop you're iterating over.
Solution 1: Starting Loop After Excluded Lines
For loopValue = 2 To 10 ' Start from the second element
' Do something
Next loopValue
This approach skips the first element and starts processing from the second.
Solution 2: Conditional Loop Iteration - EDIT : This does not work, would be great if this was an option
For loopValue = 1 To 10
If loopValue < 2 Then ' Skip the first element
Next loopValue
End If
' Do something else
' Do even more stuff
Next loopValue
Here, we check if the current value (loopValue
) smaller than 2. If it is smaller than to iterate the loopValue, If not, we perform the desired actions within the loop.
I hope this clarifies looping concepts, even for an older post!