15 October 2020

Learn to Code 1 - เฉลยแบบฝึกหัด Random Rectangles

เฉลยแบบฝึกหัด Learn to Code 1

บทที่ 6 While Loops

แบบฝึกหัด Random Rectangles 


โจทย์ Use nested loops and conditions to move around a changing world.

คำแปล จงใช้การวนลูปที่ซ้อนกันและเงื่อนไขเพื่อเคลื่อนที่รอบโลกที่มีการเปลี่ยนแปลง





เฉลย 

while !isOnClosedSwitch {

    while !isBlocked {

        moveForward()

    }

    turnRight()

}

toggleSwitch()





ขอบคุณภาพจาก Swift Playgrounds

-- ดีบี --