Post

Replies

Boosts

Views

Activity

Reply to playgrounds/ learn to code 2/ 3 gems, 4 switches/ problem with conditons in while loop
guys this the the answer for this question: var gemCounter = 0 var switchCounter = 0 func direction() {     if isBlocked && isBlockedLeft {         turnRight()     } else if isBlocked && isBlockedRight {         turnLeft()     } } func gemVar() {     if isOnGem {         collectGem()         gemCounter += 1     } }  func switchVar() {     if isOnClosedSwitch {     toggleSwitch()         switchCounter += 1 } } while !isBlocked || !isBlockedLeft ||  !isBlockedRight && switchCounter != 4{     moveForward()       direction()     if gemCounter < 3 {         gemVar()     } else if switchCounter < 4{         switchVar()     } }
Jun ’21
Reply to Roll right roll left swift playgrounds
I think this is the answer. I've checked it already. it works! while !isOnOpenSwitch {     moveForward()     if isBlocked && isBlockedRight {         turnLeft()     }     if isBlocked && isBlockedLeft {         turnRight()     }     if isBlocked && !isBlockedRight {         turnLeft()     }     while isOnGem {         collectGem()     }     while isOnClosedSwitch {         toggleSwitch()         moveForward()     } }
Jun ’21