0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

JavaScriptの繰り返し処理for文

Posted at

JavaScriptの繰り返し処理for文について

<!DOCTYPE html>
<html lang="ja">
  <head>
    <meta charset="utf-8">
    <title>繰り返し処理</title>
  </head>
  <body>
    <script src="js/loop.js"></script>
  </body>
</html>
for (var i = 1; i <=3; i++){
  console.log(i);
}

結果

47a2beb25acafa1ca22efe7919d8eb1b.png

まず変数iに1が代入され、console.logが実行されます。変数iは1なので1と実行されます。
次に増減式のi++が実行されます。この時にiに1が足されるので2になります。
次にループ継続条件式が実行されます。この時にiは2なので<=3が成り立ちそのまま継続されます。
これを繰り返して、4回目になると4<=3となり条件式が成り立たなくなるのでここで終了となります。
結果出力は1、2、3となります。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?