Нужна помощь донатом
для написания учебников Kotlin, Java, C++, C#, Go, Rust, Dart
подробности по ссылке
⊗jsPmLpNsd 158 of 504 menu
◀ ▶

Nested loops in JavaScript

Loops that you already know how to work with can be nested inside each other. For example, let's solve the following problem - display the string:

111222333444555666777888999

Single loop is not enough here - you need to run two nested loops: the first loop will iterate over the numbers, and the second one will repeat these numbers three times. Let's implement it:

for (let i = 1; i <= 9; i++) { for (let j = 1; j <= 3; j++) { document.write(i); } }

Please note: the first loop has a counter i, the second j, and if there is also the third loop, then the variable k will be its counter. These are the standard common names and should be used.

Use two nested loops to display the following string:

111222333444555666777888999

Use two nested loops to display the following string:

11 12 13 21 22 23 31 32 33
← →
↑
English▼
AfrikaansAzərbaycanБългарскиবাংলাБеларускаяČeštinaDanskDeutschΕλληνικάEspañolEestiSuomiFrançaisहिन्दीMagyarՀայերենIndonesiaItaliano日本語ქართულიҚазақ한국어КыргызчаLietuviųLatviešuМакедонскиMelayuမြန်မာNederlandsNorskPolskiPortuguêsRomânăРусскийසිංහලSlovenčinaSlovenščinaShqipСрпскиSrpskiSvenskaKiswahiliТоҷикӣไทยTürkmenTürkçeЎзбекOʻzbekTiếng Việt
We use cookies for website operation, analytics, and personalization. Data processing is carried out in accordance with the Privacy Policy.
accept all customize decline