Not understanding nested loops


Hi. I have posted my code below. I finally got it to work but am having difficulty in understanding why it worked. Here is the code:

`indent preformatted tex/*jshint multistr:true */
var text = "Jeanne is trying to learn javascript. Joanie is helpling Jeanne learn."
var myName = "Jeanne"
var hits =[];
//Assign an Integer value to the string text
for (var i=0; i if (text[i] === "J"){

    //Begin a second counter j formy  name string
 for(var j=i; j<(myName.length + i); j++)  {
if (hits.length===0){
    console.log("Your name wasn't found!");
        else {

t by 4 spaces`T
The answer printed out from console.log includes "Joanie". I assume this is because it has 6 characters which also begin with a "J".
But, I am wondering what happens if there is no 6 digits beginning with a "J" in the string. Does the computer print out "Your name wasn't found!" until an appropriate string occurs. For instance, it would read the first For loop, skip the if and the second for loop because it does not meet the conditions. Then it would go to the if (hits.length===0) condition, which would be true, and keep printing that console.log statement until it came to a 6 digit string beginning with "J"?



Is that print statement in a loop? If not, it probably won't repeat. Remove all J's and see what happens!

Question: Does X happen if I do Y?
Answer: Do Y and see if X happens.