Forum Moderators: open
for ( var i = 0; i < stringToSearch.length; ++i ) {
result=stringToSearch.indexOf( key, i );
if ( result!=-1 ) {
++count;
//enable one and only one of the lines below.
i=result+1;
//i=result++;
}
else break;
}
alert (stringToSearch+" "+key+" "+count);
You will get interesting results
i=j+1 means that i becomes the value of j plus one, j unaffected
i=j++ means that j is incremented and the i is set to the new j (which is old j+1)
i=++j (in c++, unsure about javascript) means that i becomes the value of (old) j, then j is incremented.
Eg) all examples start with j = 3
i=j+1; i should be 4, j should 3
i=j++; i should be 4, j should 4
i=++j; i should be 3, j should 4