Qlik Community

Qlik Sense App Development

Discussion board where members can learn more about Qlik Sense App Development and Usage.

Announcements
Make your voice heard! Participate in the 2020 Wisdom of Crowds® Survey. BEGIN SURVEY
senior_freshmen
New Contributor III

(Semantic) Error in for Loop with a if-condition

Good Day,

im very new in this Topic and i can't explain whats wrong with this tiny part of a code.

I receive the Error Message:

Semantic error
The control statement is not correctly matched with its corresponding start statement
next counter

 

Mtart_G is a column of a table which I've created earlier in the code

let counter = 0; 
let boolean = 'false' ; 

for counter = 1 to 10 //count(Mtart_G); if Mtart_G = 151 then boolean = 'true' next counter ;

Sincerely,

6 Replies
Highlighted

Re: (Semantic) Error in for Loop with a if-condition

You need END IF

let counter = 0; 
let boolean = 'false' ; 

for counter = 1 to 10    //count(Mtart_G);
  
	if Mtart_G = 151 then 
	boolean = 'true'
        END IF;
 
next counter ;
Highlighted
senior_freshmen
New Contributor III

Re: (Semantic) Error in for Loop with a if-condition

Ok thanks at all, that was a simple fault.

The Syntax is correct, but somehow it doesn't work at all how it was planned.
My plan was to search an specific value in the Column 'Mtart'. When its true boolean should be 'true' too. But it doesnt.
Could you help me with this too?
Highlighted

Re: (Semantic) Error in for Loop with a if-condition

Not really sure what you have for  Mtart_G. May be you need to use it with $()

let counter = 0; 
let boolean = 'false' ; 

for counter = 1 to 10    //count(Mtart_G);
  
	if $(Mtart_G) = 151 then 
	boolean = 'true'
        END IF;
 
next counter ;
Highlighted
senior_freshmen
New Contributor III

Re: (Semantic) Error in for Loop with a if-condition

No, doesn't work.
To make sure we dont have a missunderstanding. Mtart_G is a column in an table, filled with numbers. I want to set boolean = 'true' if the Loop finds the value '151' in this column.
Highlighted

Re: (Semantic) Error in for Loop with a if-condition

Would you be able to share a sample where I can see what you have? I am just seeing half of the script and that to without knowing your data... if you can mock up your scenario for me, I should be able to help you better

Highlighted
MVP & Luminary
MVP & Luminary

Re: (Semantic) Error in for Loop with a if-condition

You could use the following to detect if a certain value exists within the datamodel:

let boolean = if(fieldindex('Mtart_G', 151), dual('true', 1), dual('false', 0));

If you need to check this by key-fields within a certain table you will need to ensure a certain order of your loadings or you need to load it from this table - whereby in this case the check might be already done within the origin load.

- Marcus