'코드'
논리 연산자 !(NOT) = !a a가 true이면 false, false이면. True 반환
조건문
if <조건식> {
<조건이 참일 때 실행할 구문>
} else {
<조건이 거짓일 때 실행할 구문>
논리 연산자와 조건문을 사용하여 코드를 완성했습니다.
for i in 1 ... 4 {
moveForward()
collectGem()
}
turnLeft()
turnLeft()
if isOnGem {
turnRight()
moveForward()
moveForward()
collectGem()
} else {
moveForward()
}
if isOnGem {
turnRight()
moveForward()
moveForward()
collectGem()
} else {
moveForward()
}
if isOnGem {
turnRight()
moveForward()
moveForward()
collectGem()
} else {
moveForward()
}
if !isOnGem {
turnRight()
moveForward()
moveForward()
collectGem()
} else {
moveForward()
}
'Playgrounds'플레이그라운드'' 카테고리의 다른 글
Playgrounds '플레이그라운드' 11. (0) | 2024.05.18 |
---|---|
Playgrounds ‘플레이그라운드’ 10. (0) | 2024.05.17 |
Playgrounds '플레이그라운드' 8. (0) | 2024.05.16 |
Playgrounds '플레이그라운드' 7. (0) | 2024.05.15 |
Playgrounds '플레이그라운드' 6. (0) | 2024.05.15 |