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?

JavaScript 条件分岐(if)

Posted at

はじめに

ifとswitchについて理解はしているのですが、書き方がごっちゃになることがあるので自分用まとめです。

ifサンプルコード

$score = 100;

if ($score === 100) {
    echo "excellent!!" . PHP_EOL;
} else if ($score >= 80) { //elseifじゃなくてelse if
    echo "Great!" . PHP_EOL;
} else {
    echo "もうすこしがんばりましょう" . PHP_EOL;
}   
excellent!!

比較演算子

>=  //以上
<=  //以下
>   //超過
<   //未満
=== //等しい
!== //等しくない

複数条件

&& and //なおかつ
|| or  //もしくは
!      //ではない

returnで処理の中断

ifの中でreturnを使用するとifを抜けます。

おわりに

基礎なんでちゃんと覚えたいですね。

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?