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 1 year has passed since last update.

複数の条件式

0
Last updated at Posted at 2025-03-15

かつ

今回は、複数の条件を組み合わせる方法を学んでいきます。
まずは、かつについてです。かつ&&で表します。
条件1 && 条件2条件1かつ条件2という意味で、複数の条件がすべてtrueならtrueになります。
右の図の10より大きいかつ30より小さいは、10 < x < 30と書くことは出来ません。このようなときは&&を使いましょう。

image.png

または

次は「または」を表す記号です。「または」は「||」で表します。
「条件1||条件2」は「条件1または条件2」という意味です。 この場合は、複数の条件のうち1つでもtrueならtrueになります。
image.png

組み合わせの具体例

if文を使った「かつ」の具体例を見てみましょう。
下の図では、「number >= 10」、「number < 100」どちらも true なので処理が実行されています。
image.png

例題

「かつ」を用いて、if文を作成する例題に取り組んでみましょう。

qiita.js
const age = 24;

//「定数ageの値が20以上かつ30未満」という条件のif文を作成してください。 

//また、その中で文字列「私は20代です」を出力してください。
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?