Swift Playgrounds Study: Day7

Result
: 『Learn to Code1』 While Loops, Creating Smarter While Loops → Algorithms Roll Right, Roll Left

Finally, I’ve just compleated 『Learn to Code1』!

“The Final Chapter” Algorithm

I learned and noticed many things in today’s study.

Especially, I understood that code is extremely powerful.

For example, this code is very impressive.

func navigateAroundWall() {
if isBlockedRight {
moveForward()
} else {
turnRight()
moveForward()
}
}

^ you can use code blocks in Medium : Cmd(Ctrl)-Alt-6

Feel grateful for this moment

The following code is my solution for the most final task “Algorithms Roll Right, Roll Left”.
I know, It’s not good code and infinite loop. However I solved the task.
Don’t know why,,,

Of course, I have to tweak it.

func navigateAroundWall() {

if isBlockedRight {
moveForward()
} else {
turnRight()
moveForward()
}

if isBlocked && isBlockedRight {
turnLeft()
}
}
while !isOnGem { 
while !isOnGem && !isOnClosedSwitch {
navigateAroundWall()}

if isOnGem {
collectGem()


} else if isOnClosedSwitch {
toggleSwitch()

}

}

^only as a guide


In conclution 『Learn to Code1』

  • An awesome teaching materal for me. 
    I am a truly beginner for programing. Swift is (kind of ) my first programing language.
  • I don’t know everyone could done 『Learn to Code1』because It’s not super easy and not super short program. 
    Need motivation. I’ve always wanted to improve my programing skills in the past few years.
  • Anyway, I recommend it💁

Thank you swift playgrounds.
I am becoming a fan of programing.

Continue.

One clap, two clap, three clap, forty?

By clapping more or less, you can signal to us which stories really stand out.