Iam not sure why it crash


#1


/*jshint multistr:true */
text = "Papa misses mama so much.\
Papa is hungry, Papa wanna eat";

var myName = "Papa";
var hits = [];

for (var i = 0; i < text.length; i++)
{
   if(text[i] === "P")
   {
       for(var j = i; j + myName.length; j++)
       {
        hits.push(text[j]);
        hits[0];
       }
   }
}


#2

you have an infinity loop, here:

j + myName.length

this is your second loop condition, this are just integers added together? That will always evaluate to true


#3

2 posts were split to a new topic: Question about second for loop


#5

It's an infinite loop


#6

This topic was automatically closed 7 days after the last reply. New replies are no longer allowed.