Qlik Community

App Development

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

Announcements
See why Qlik was recognized for the seventh year in a row – and discover how we can help you tackle your data integration challenges. Get the report
cancel
Showing results for 
Search instead for 
Did you mean: 
senior_freshmen
Contributor III
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,

Labels (1)
6 Replies
sunny_talwar

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 ;
senior_freshmen
Contributor III
Contributor III
Author

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?
sunny_talwar

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 ;
senior_freshmen
Contributor III
Contributor III
Author

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.
sunny_talwar

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

marcus_sommer
MVP & Luminary
MVP & Luminary

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