Skip to main content
Announcements
NEW: Seamless Public Data Sharing with Qlik's New Anonymous Access Capability: TELL ME MORE!
cancel
Showing results for 
Search instead for 
Did you mean: 
Miles_Dyson
Contributor III
Contributor III

When to specify variable name after the 'Loop' or 'Next' statements

Hello experts,

What is the best practice when it comes to whether or not to specify the loop variable name after the 'Loop' statement in the Do..Loop or after the 'Next' statement in the For..Next & For Each..Next loops. Are there scenarios that call for explicit inclusion or exclusion of the loop variable name at this position?

Thank you

Labels (6)
1 Solution

Accepted Solutions
marcus_sommer

In my experience it's in Qlik technically not necessary. I have a faint remembering of struggling with specifying variables by the next-statements in my first days but probably I made just stupid mistakes.

Nevertheless by using many (nested) loops over a lot of rows and/or even multiple script-tabs a specifying of the next-statements might be helpful to follow the script-stream. Personally I prefer to keep the script quite compact by using multiple layer + applications + tabs as well as outsourcing scripts in variables and routines and working with indentation and therefore I have no need for such measurements.

View solution in original post

5 Replies
Miles_Dyson
Contributor III
Contributor III
Author

I think I may have figured out an answer to my question...which is Nested Loops. I am thinking they are a good example of when we need to specify the loop var names after the Loop & Next statements. Unless I am wrong somehow.

marcus_sommer

Even by nested loops it's not necessary to specify the iterator-variable by the next-statement - the parser relates to the belonging positions - for/next is like using brackets ().

Miles_Dyson
Contributor III
Contributor III
Author

I see, thank you Marcus...so does this mean specifying the iterator-variable by the next-statement is entirely optional?

marcus_sommer

In my experience it's in Qlik technically not necessary. I have a faint remembering of struggling with specifying variables by the next-statements in my first days but probably I made just stupid mistakes.

Nevertheless by using many (nested) loops over a lot of rows and/or even multiple script-tabs a specifying of the next-statements might be helpful to follow the script-stream. Personally I prefer to keep the script quite compact by using multiple layer + applications + tabs as well as outsourcing scripts in variables and routines and working with indentation and therefore I have no need for such measurements.

Miles_Dyson
Contributor III
Contributor III
Author

Ok, I see. Thank you for taking time to explain & put things into perspective. I have a better understanding now.