0
0

More than 1 year has passed since last update.

switch文とif文の違い 参考サイト

Last updated at Posted at 2022-01-27

switch文とif文の使い分け方

switch 文を使うか、if文を使うかを迷ったときには、条件がどうなっているかで使い分けます。

if 文に向いている条件

変数の値がある特定の値よりも大きいかったり小さいさかったりなど、条件に幅がある時
条件に変数が複数使われている時
複数の条件が組み合わされている時
分岐する処理が2つしかない時

switch 文に向いている条件

変数がある値になる時に処理を分ける。しかも、その値が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