Hi team, I’m new to swift - just getting started - and as such have been working through swift playgrounds on iPad however at the final exercise “ roll left, roll right” I’m having an issue escaping my while loop.
This is my current code:
while !(isBlocked && isBlockedLeft && isBlockedRight) {
moveForward()
if isBlocked && isBlockedLeft {
turnRight()
} else if isBlocked {
turnLeft()
}
if isOnGem {
collectGem()
} else if isOnClosedSwitch {
toggleSwitch()
}
}
problem being that when Byte reaches the end of the maze and is blocked front, left, and right the code doesn’t exit as (I believe) it should but rather byte turns and loops the maze again.
what am I missing?
This is my current code:
while !(isBlocked && isBlockedLeft && isBlockedRight) {
moveForward()
if isBlocked && isBlockedLeft {
turnRight()
} else if isBlocked {
turnLeft()
}
if isOnGem {
collectGem()
} else if isOnClosedSwitch {
toggleSwitch()
}
}
problem being that when Byte reaches the end of the maze and is blocked front, left, and right the code doesn’t exit as (I believe) it should but rather byte turns and loops the maze again.
what am I missing?