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 5 years have passed since last update.

JavaScript勉強の記録その4: while文

0
Last updated at Posted at 2020-01-12

JavaScriptでwhile文

while (条件式) {条件式がTrueである間、行いたい処理;}
と書くことでループ処理ができる。

以下の例ではhpという変数が0以上の間はループ処理をして、hpがなくなるまで数字を減らしていきます。

index.js
let hp = 150;

while (hp >= 0) {
  console.log(`${hp} HP left!`);
  hp -= 15;
}

//150 HP left!
//135 HP left!
//120 HP left!
//105 HP left!
//90 HP left!
//75 HP left!
//60 HP left!
//45 HP left!
//30 HP left!
//15 HP left!
//0 HP left!
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?