일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | |||||
3 | 4 | 5 | 6 | 7 | 8 | 9 |
10 | 11 | 12 | 13 | 14 | 15 | 16 |
17 | 18 | 19 | 20 | 21 | 22 | 23 |
24 | 25 | 26 | 27 | 28 | 29 | 30 |
31 |
- Swift
- allege
- 렛츠톡 첫 화면
- obliged
- 2대 연결
- progamming
- 해당 비즈니스 및 사이트명을 포함할 수 있도록 페이지 텍스트를 편집하세요 - wix.com
- crank up and down
- Grammarly
- 신세지다
- 컴터 연결
- 인앱 결제
- feel torn
- Playgrounds
- 코딩
- BASIC
- 구글이 좋아하는 강한 SEO 작성 방법
- Learning
- 맥
- Generalizing a Funcetion
- SwiftUI
- collect the total
- 기초
- Uniting Worlds
- Polite
- Playground
- Making Your Own Portals
- Connect and Solve
- 코린이
- coding
- Today
- Total
IT
day 4 - while 본문

Yes, I can use the condition after the while statement.
Quest 1

while !isBlocked {
moveForward()
if isOnOpenSwitch {
moveForward()
} else if isonClosedSwitch {
toggleSwitch ()
}
}
while 스테이트먼트 쓸때 첫 조건은 그냥 앞으로 나아가라고 해도 된다. 이 점을 생각해내기가 어려웠음.
Quest 2

func turnAndCollectGem() {
moveForward()
turnLeft()
moveForward()
collectGem()
turnRight()
}
while !isBlocked {
turnAndColllectGem ()
}
tip.
In coding, it's important to study a problem and choose from one of several available solutions. Sometimes, one approach can work just as well as another. Other times, an approach might end up being more efficent, reusable, or adaptable than others.
Quest 3

while !isBlocked {
moveForward()
if isOnClosedSwitch {
toggleSwitch()
turnRight()
} else if isOnOpenSwitch {
turnRight()
}
}
Quest 4

moveForward()
while isOnGem {
collectGem()
turnLeft()
moveForward()
if !isOnGem {
turnRight()
moveForward()
}
}
Right on!
Developing your own solutions for new problems enables you to figure out what types of tools work in certain situations. As your skills grow, you'll be able to choose those tools more quickly and intelligently. How awesome is that?
Quest 5

my answer )
for i in 1 ... 5 {
moveForward()
if isOnGem || isOnClosedSwitch {
collectGem()
toggleSwitch()
}
}
turnRight()
moveForward()
turnRight()
for i in 1 ... 5 {
moveForward()
if isOnGem || isOnClosedSwitch {
collectGem()
toggleSwitch()
}
}
turnLeft()
moveForward()
turnLeft()
for i in 1 ... 5 {
moveForward()
if isOnGem || isOnClosedSwitch {
collectGem()
toggleSwitch()
}
}
comment ) I hope it would be more simple but.. no time to think at this time.
Quest 6

while loop 를 두번이나 쓸 수 있다. 바깥 while, 안 while 이라고 불린다.
while !isBlocked {
while !isonGem {
moveForward()
}
collectGem()
turnLeft()
}
그러니까 첫번째 while에서 '막히지 않았다'면 다음 while을 진행한다.. - 이런 식으로 해석해야 할 것 같다.
그리고 이제 Gem이 나오면 'isonGem' 이 되니깐 식이 밑으로 갈 수가 있다. 결국 while + while 조건이라고 생각.
if 문과 쓰임이 같다.
tip) Be careful, though. if a while loop Boolean condition is never false, your code will run forever in an infinite loop, which can make your computer freeze.
Quest 7

while !isOnClosedSwitch {
while !isBlocked {
moveForward()
}
turnRight()
}
toggleSwitch()
tip) there was a problem at the end of this road. so I simply moved the code 'toggleSwitch()' to the end from the after the 'turnRight()'
Quest 8
Remember, it's okay if you don't get it on your first try! Professional coders hardly ever get things right the first time around.

solution )
while !isBlocked {
moveForward()
while isOnClosedSwitch || isOnGem {
toggleSwitch()
if isOnGem{
collectGem()
}
}
if isBlocked {
turnRight()
moveForward()
}
}