here for(x in s) work as for loop here they count the no of character which are not equal to i.
first(x=0) if condition fail so else condition will run which is pass when x=1 if condition true due to i!=n it increment in l so it will count all char which are not equal to i