JS Dasar: 34. For loop

by istiq20

HTML

<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <title>For loop</title>
  </head>
  <body>
    <script>
      
      // perulangan tanpa henti
      // for (; ;) { alert("For loop") }

      // perulangan dengan kondisi
      let counter = 1;
      for (; counter <= 10; ) {
        document.writeln(`<p>Perulangan pertama ke ${counter}</p>`)
        counter++;
      }

      // perulangan dengan init statement
      for (let counter = 1; counter <= 10; ) {
        document.writeln(`<p>Perulangan kedua ke ${counter}</p>`)
        counter++;
      }

      // perulangan dengan post statement
      for (let counter = 1; counter <= 10; counter++) {
        document.writeln(`<p>Perulangan ketiga ke ${counter}</p>`);
      }

    </script>
  </body>
</html>