Skip to main content
Announcements
Have questions about Qlik Connect? Join us live on April 10th, at 11 AM ET: SIGN UP NOW
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

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