# Second for loop not pushing to values

#1

I know my problem is the exact same as everyone else's, but I can't figure out what I'm missing here. Please if someone could blow up this brick wall I'm banging my head against...

var text = "Hello my name is Paul. I think I have to capitalize the paul or else it won't recognize Paul. Seems like a weird thing, but computers are infuriatingly logical. Much like Paul is.";
var myName = "Paul";
var hits = [];

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

#2

`i` will never be greater than the length, even if it is 0.

#3

I'm not sure what the correct answer is, but at least I know where to focus on. Thanks!

Not sure why it lets you go on to step 5 when step 4 is broken.

#4

Wait, that can't be right. i will be greater than the length of the text because the text length is finite. Probably around 140 characters. So when i is incremented to 141 then the loop will end.

#5

Here was my solution that worked, hope it helps others:

for (var i=0; i < text.length; i++){

not sure why it works. maybe the middle part isn't the ending condition but the continuing condition.

Also you can't say "i = i++". even though the first example we're taught is i=i+1.

#6

The loop only continues while that condition is true.

That will increment i, and then assign the original value to i, undoing the incrementing. You could use prefix ++, but there would be no point in doing the assignment after having already incremented it.

`i = ++i` is equivalent to:
`i = i + 1; i = i`

and `i = i++` is equivalent to:
`temp = i; i = i + 1; i = temp;`
(except that the temp variable is not created)

#7

You have no idea how much this just helped me. Thank you!
I was banging my head against the same brick wall. My issue was `j< (myName.length + 1);`
I had it as `i + j<myName.length + 1;` (no parentheses)

#8

Although my code works, but I can never understand how the second for loop works. Can anyone please explain to me?