hello all,
I am at the beginning of learning swift with the ipad playgrounds.
in the chapter, where you have to go through a labyrinth till you collected 3 gems and toggled 4 switches, I have the following problem.
ar numberGem = 0
var numberSwitch = 0
}
func direction() {
if isBlocked && isBlockedLeft {
turnRight()
} else if isBlocked && isBlockedRight {
turnLeft()
}
}
func gemSwitchVar() {
if isOnGem {
collectGem()
numberGem += 1
} else if isOnClosedSwitch {
toggleSwitch()
numberSwitch += 1
}
}
while numberGem < 4 && numberSwitch < 5 {
gemSwitchVar()
direction()
moveForward()
}
the while loop always stops after the figure collected 3 gems. It does not continue till it also toggled 4 switches. I always thought that with AND both conditions had to be fullfilled. And the OR operator would display the behaviour it does now.
I had the same problem with a while loop in an earlier chapter where I tried a while loop like
while !isBlocked && !isBlockLeft && !isBlockedRight
to make my figure walk till the end of the course, which was blocked in the upper way.
Where is my thought error.