
ex) 논리 연산자가 뭐예요? 왜 써요? 종류는요?While loop is A block of code that runs for as long as a given condition is true. When the condition changes to false, the loop stops running. While 반복문은 주어진 조건이 true인 동안 실행되는 코드 블럭이다. 조건이 false로 바뀌면 반복은 멈춘다!
When you're hammering a nail, you can't just hit it a certain
number of times and expect it to go all the way in.
Instead, you continue hitting the nail while the nail is
sticking out.
You can use a while loop to repreat a command,
or set of commands, while a condition is true.
while nailIsStickingOut {
hammerNail()
}
Using while loops is already making your code simpler. By pairing a while loop and conditional code, you can write code that's much more adaptable.
While Loops part words
a small metal spike with a broadened flat head, driven typically into wood with a hammer to join things together or to serve as a peg or hooka thin, pointed piece of metal, wood, or another rigid material.unable to bend or be forced out of shape; not flexiblebecome larger in distance from side to side; widenbe extremely noticeableable to be modified for a new use or purposemake partial or minor changes to (something), typically so as to improve it or to make it less extremeA characteristic of code that allows it to be used in different situations within an application.(예제 문제들 중 더 클린하게 작성할 수 있을 지 고민이 필요한 코드 모음)
Turned Around

func collectGemAndTurnLeftAndMoveForward() {
collectGem()
turnLeft()
moveForward()
}
for i in 1 ... 4 {
moveForward()
while isOnGem {
collectGemAndTurnLeftAndMoveForward()
}
if !isBlocked && !isBlockedLeft && !isBlockedRight {
turnRight()
}
}
Land of Bounty (switch/gem 개수 바뀜)

func moveForwardAndCollectOrToggle() {
if isOnClosedSwitch {
toggleSwitch()
} else if isOnGem {
collectGem()
} else {
moveForward()
}
}
for i in 1 ... 3 {
while !isBlocked {
moveForwardAndCollectOrToggle()
}
if isBlocked && isBlockedLeft {
turnRight()
moveForward()
turnRight()
} else if !isBlockedLeft && !isBlockedRight {
turnLeft()
moveForward()
turnLeft()
}
}
You're Always Right

while !isOnGem {
while !isBlocked {
if isOnClosedSwitch {
toggleSwitch()
} else {
moveForward()
}
}
turnRight()
}
collectGem()
collectGem()을 while 조건문 안에 넣어보고 싶은데 방법이 없을까...? 🤔 While Loops(While 반복문)는 주어진 조건이 참(true)일 경우에만 반복하는 코드이다.
22.09.30, 10.03, 12 TIL 끝!
썸네일은 Banner Maker로 제작하였습니다.
기초를 탄탄히!! 잘보았습니다! 👍🏻