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: 
marco_puccetti
Partner - Creator
Partner - Creator

Loops statement

Hello i need a statement different from for next, what can i use?

Thanks

Marco

1 Solution

Accepted Solutions
petter
Partner - Champion III
Partner - Champion III

You can loop with statements in a control statement like with:

     DO WHILE i<10

         i = i + 1;

     LOOP;

or

     DO

        i = i + 1;

    LOOP WHILE i<10;

but you can use a loop inside a LOAD statement which gives an order or several order of magnitudes faster looping:

SomeRows = Ceil( Rand() * 100 ) + 100;

DATA:

LOAD

     RowNo() AS RowNo,

     IterNo() AS IterNo

WHILE

     IterNo() <= 10

AUTOGENERATE

     $(SomeRows);

And as you see from the above example you can also use AUTOGENERATE to "loop" a certain number of times.

View solution in original post

9 Replies
Anonymous
Not applicable

Depends what you are trying to do..... maybe while ?

marco_puccetti
Partner - Creator
Partner - Creator
Author

But while exists as statement? Which is the syntax?

Thanks

Marco

Anonymous
Not applicable

The QV Desktop Help is very good and explains it in detail.

And as I said, it depends what you are trying to do....your question was a trifle vague.

petter
Partner - Champion III
Partner - Champion III

You can loop with statements in a control statement like with:

     DO WHILE i<10

         i = i + 1;

     LOOP;

or

     DO

        i = i + 1;

    LOOP WHILE i<10;

but you can use a loop inside a LOAD statement which gives an order or several order of magnitudes faster looping:

SomeRows = Ceil( Rand() * 100 ) + 100;

DATA:

LOAD

     RowNo() AS RowNo,

     IterNo() AS IterNo

WHILE

     IterNo() <= 10

AUTOGENERATE

     $(SomeRows);

And as you see from the above example you can also use AUTOGENERATE to "loop" a certain number of times.

marco_puccetti
Partner - Creator
Partner - Creator
Author

The QV Desktop Help is not working on my version, so i ask in this forum.

Thanks

Marco

Peter_Cammaert
Partner - Champion III
Partner - Champion III

do while | until condition

   statements

loop

or

do

  statements

loop while | until condition

See the article on do...loop in QV Desktop Help

maxgro
MVP
MVP

syntax is, copied from QV Desktop Help

Do..loop

The do..loop control statement is a script iteration construct which executes one or several statements until a logical condition is met. The syntax is:

do[ ( while | until ) condition ] [statements]
[exit do [ ( when | unless ) condition ] [statements]
loop[ ( while | until ) condition ]

Where:

condition

is a logical expression evaluating to true or false.

statements

is any group of one or more QlikView script statements.

The while or until conditional clause must only appear once in any do..loop statement, i.e. either after do or after loop. Each condition is interpreted only the first time it is encountered but is evaluated for every time it encountered in the loop.

If an exit do clause is encountered inside the loop, the execution of the script will be transferred to the first statement after the loop clause denoting the end of the loop. An exit do clause can be made conditional by the optional use of a when or unless suffix.

Since the do..loop statement is a control statement and as such is ended with either a semicolon or end-of-line, each of its three possible clauses (do, exit do and loop) must not cross a line boundary.

Examples:

// load files file1.csv..file9.csv

Set a=1;

Do while a<10

Load * from file$(a).csv;

Let a=a+1;

Loop

Peter_Cammaert
Partner - Champion III
Partner - Champion III

Reinstall QV Desktop.

or

consult the QlikView Reference Manual in C:\ProgramData\QlikTech\QlikView Documentation\Reference Manual. It contains the same and much more as QV Desktop Help.

Peter

marco_puccetti
Partner - Creator
Partner - Creator
Author

Thanks.

Marco