
ex) 논리 연산자가 뭐예요? 왜 써요? 종류는요?Logical Operators isa type of an operator that you can use to make your conditional code more specific. 조건문을 더 명확하게 만드는 부호(기호)이다.
Earlier, you used an if statement to plan for different situations.
But what if you could make your conditional code even more powerful?
if lightIsGreen {
moveForward()
} else {
wait()
}
In code, an operator is a symbol which represents an action.
The Logical AND (&&) Operator
This is code runs only if all conditions are true.
if blocked AND on a gem:
collect gem
turn around
if isBlocked && isOnGem {
collectGem()
turnAround()
}
The Logical OR (||) Operator
This code runs if at least one condition is true.
if blocked AND on a gem:
collect gem
turn around
if isBlocked && isOnGem {
collectGem()
turnAround()
}
The Logical NOT (!) Operator
This operator changes a condition to its opposite.
For example, if onGem is true, !onGem is false.
if NOT blocked:
fly away
if !isBlocked {
flyAway()
}
Each of these three operators changes conditions in its own specific way:
The Logical NOT (!) Operator reversed a Boolean(A type that has a value of either true or flase. For example 9<7 returns a Boolean value of false because 9 is not less than 7) Value.
Logical Operators part words
reasoning conducted or assessed according to strict principles of validity 강력한 적합성의 원칙에 따라 수행하거나 평가된 추론, 논리of or according to the rules of logic or formal argument 논리 규칙이나 정해진 논쟁에 따르는 것, 논리적the action of thinking about something in a logical, sensible way 어떤 것에 대해 논리적이고 현명한 방법으로 생각하는 행위, 추론organize and carry out 조직화하고 실행하는 것, 수행하다evaluate or estimate the nature, ability, or quality of 성질, 능력, 품질을 평가하거나 추정하는 것, 평가하다chosen in accordance with wisdom or prudence; likely to be of benefit 지혜나 ~를 이용하여 선택하는 것, 이익이 되도록, 현명하다conformity or agreement 순응 혹은 동의compliance with standards, rules, or laws 관습, 규칙이나 법에 순응하는the action or fact of complying with a wish or command 요청이나 명령을 따르는 사실이나 행동, 준수arrange into a structured whole; order 구조화된 것을 배열하는 것, 조직화하다put (things) in a neat, attractive, or required order 어떤것을 정돈되거나, 특징이나, 주어진 조건에 의해 놓는 것, 배열하다(of a place or thing) arranged in an orderly, tidy way 순서나 방법에 맞춰서 배열된 것, 정돈된(of a thing) having beneficial qualities or features that induce someone to accept what is being offered 어떤 사람이 제공된 것을 수용하도록 설득하는 특별한 특성 혹은 특징, 표면적인 특징?(흥미있는, 매력있는)(예제 문제들 중 더 클린하게 작성할 수 있을 지 고민이 필요한 코드 모음)

func comeBack() {
turnLeft()
moveForward()
moveForward()
collectGem()
turnLeft()
turnLeft()
moveForward()
moveForward()
turnLeft()
}
for i in 1 ... 4 {
moveForward()
if !isOnGem {
comeBack()
} else {
collectGem()
}
}

for i in 1 ... 7 {
moveForward()
if isOnGem {
collectGem()
}
if isBlockedLeft {
turnRight()
while !isBlocked {
moveForward()
}
if isBlocked && isOnClosedSwitch {
toggleSwitch()
}
turnLeft()
turnLeft()
while !isBlocked {
moveForward()
}
turnRight()
}
}

for i in 1 ... 8 {
moveForward()
if isOnClosedSwitch && isOnGem {
collectGem()
toggleSwitch()
turnRight()
moveForward()
moveForward()
collectGem()
turnRight()
turnRight()
moveForward()
moveForward()
turnRight()
} else if !isOpenSwitch {
toggleSwitch()
turnLeft()
} else if isOnGem {
collectGem()
}
}
Logical Operators(논리 연산자)는 조건문의 조건을 세부하게 나타낼 수 있는 부호 이다.
ex)
22.09.22, 23, 26, 27 Playgrounds TIL 끝!
썸네일은 Banner Maker로 제작하였습니다.