'how for create double loop in javascript with if condition

for (var o = 1; o <= 10000; o++) {
    alert("also result "+o)
for (var p = 1; p <= 10000; p++) {
    alert("result "+p)
    if (p % 11 == 0) {
        break;
    }
    }
}

i want to result like this

result 1 also result 1

result 2 also result 1

result 3 also result 1

result 4 also result 1

result 5 also result 1

result 6 also result 1

result 7 also result 1

result 8 also result 1

result 9 also result 1

result 10 also result 1

result 11 also result 2

result 12 also result 2

result 13 also result 2

result 14 also result 2

result 15 also result 2

result 16 also result 2

result 17 also result 2

result 18 also result 2

result 19 also result 2

result 20 also result 2

result 21 also result 3

result 22 also result 3

result 23 also result 3

result 24 also result 3

result 25 also result 3

result 26 also result 3

result 27 also result 3

result 28 also result 3

result 29 also result 3

result 30 also result 3

how to create loop in javascript,,please help me?



Solution 1:[1]

This task can be solved without nested loops

for (let i = 1; i <= 10000; i++) {
  console.log(`result ${i} also result ${Math.floor((i - 1) / 10) + 1}`)
}

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Polyakov Egor