Infinite Loop on second "for" loop?


#1

I've been playing with this coding, reading the forum and watching tutorials for hours now and I can't understand why my code isn't working. Whenever I go to input it, the page crashes. Q&A says this is because it's an infinite loop. Can anyone tell me what I'm doing wrong?

CODE:
var text= "Blah blah blah blah blah Sophie blah blah blah Sophie blah blah blah Sophie.";
var myName = "Sophie";
var hits = [];

for(var a = 0; a < text.length; a++){
if(text[a]=="S"){
for(var b = a; b < (myName.length + b); b++){
hits.push(text[b]);
}
}
};

Thank you in advance!


#2

Hey kolans,

in your second for statement, the second part of it should be using the a variable instead of using b. The use of your b variable is whats causing the infinite loop. Since b is comparing to something, it needs an outside, defined variable to compare itself to, like a.

Hope this helps!