Swift Playground - Round up the switches (using While & if conditions)

Another solution for easy understanding, hope it helps.

var gemCounter = 0

var switchCounter = 0

while gemCounter >= switchCounter {

    moveForward()

    if isBlocked && isBlockedLeft {

        turnRight()

    }

    while isOnGem {

        collectGem()

        gemCounter += 1

    }

    while isOnClosedSwitch && switchCounter !=  gemCounter {

        toggleSwitch()

        switchCounter += 1

        if switchCounter == gemCounter {

            

            switchCounter += 1

        }

        

    }

Another solution to what problem ?

I'm here wondering as well, I don't see a prior question but it seems they're assuming someone else is doing the same exercise as them.

Solution for swift playground-question of *Round up the switches chapter .

Swift Playground - Round up the switches (using While & if conditions)
 
 
Q