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

今回は、真偽値と比較演算子について学習していきます。

真偽値

右の図のように、if文の条件式の部分を出力してみると、trueと出力されています。
このtrueが真偽値と呼ばれるものです。
真偽値にはtruefalseという2つの値しか存在しません。
条件式が、成り立つとtrue、成り立たなければfalseという真偽値に置き換わります。

image.png

if文と真偽値

下の図のように、if文は条件式がtrueであれば処理が実行され、falseであれば実行されません。

image.png

比較演算子

条件式に使った、大小を比べる演算子「>」は比較演算子と呼ばれる、大小比較の記号です。
「a < b」は、aの方がbより小さいときtrue、大きいときfalseになります。
また「a <= b」とすると、aの方がbより小さいまたは等しい(つまりb以下)のとき true になります。
以下の図を確認し、比較演算子をしっかりと抑えておきましょう。

image.png

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?