[Swift] Summary about Bool type

Introduction

This time, we will output about Bool type. Because, although I can explain the String type and ʻInt type`, I couldn't verbalize the Bool type, so I will output it again here.

What is Bool type?

There is a concept of truth value in the world of programming languages. The one that represents the truth value is Bool type. There are true and false literals that represent truth values, and when you assign a true or false to a variable, the Bool type is assigned as an implicit type.

var sample = true //Bool type

How to use Bool type

Bool type is used for logical operation. An operation is to perform some processing on the data and obtain the resulting value.

Logical operations and operators

type Contents Operator to use
denial Reverse the truth of the truth value Prefix operator!
Logical sum True if either of the multiple truth values is true Medium value operator ||
Logical AND True if both of the multiple truth values are true Neutral operator&&

Example of logical operation

//denial
let sample1 = true //true (true)
let sample2 = !sample1 //false (false)

//Logical sum
sample1 || sample2 //true because sample1 is true

//Logical AND
sasmple1 && sample2 //sample1 is true, but sample2 is false, so false

Recommended Posts

[Swift] Summary about Bool type
[Swift] Type type ~ Enumeration type ~
[Swift] About generics
[Swift] Type type ~ Structure ~
[Swift] Type components ~ Type nesting ~
Swift Iterative Sentence Summary
[Swift] Type component ~ Subscript ~
[Swift] Type design guidelines
[Swift] Type component ~ Initializer ~
[Swift] Shared enumeration type
[Swift] About enumeration types
[Swift] Type type-Class sequel-
[Swift] About protocol extension
Personal summary about Java
Chart type 2nd summary
[Java] About enum type
About [Cocoa] [Swift] AirPlay 2
[Swift] Type component ~ Method ~
[Swift] [Beginner]] About range operators
[Swift] Simple screen transition summary
Swift conditional branch statement summary
[Swift] About asynchronous processing "Operation"
[Swift] Type type-Class first part-
About the explanation about functional type
[Swift] I thought about compare
[Swift] Type component ~ Property Part 2 ~
Great Swift pointer type commentary
[Swift] "for-in statement" about iterative processing
A little summary about typesafe config
Summary about the introduction of Device