mardi 21 août 2018

If statement inside of For loop skips counter [on hold]

First of all, I am sorry if it was being answered. I tried to look up but couldn't find.

I have two for loops and inside them, there is an if statement. For loops works great and does what I want them to do. But in the second for loop sCounter gives 1, 2 then if statement sCounter starts from 2. I will give the output I am getting after the code.

for (let counter = 1; counter <= 10 ; counter++) {
      for (let sCounter = 1; sCounter <= 26; sCounter++) {
        console.log(sCounter);
        if ( something === somethingelse && something2 === somethingelse2) {
            console.log('YAY' + sCounter);
        }
    }
}

Output I am getting;

// 1 2 YAY2 3 YAY3 4 YAY4 5 YAY5 6 YAY6 . . .

Output I was expecting;

// 1 YAY1 2YAY2 3 YAY3...

Aucun commentaire:

Enregistrer un commentaire