這一關,我們又是一個簡單的小游戲。
你再仔細看看,寶石的分布和傳送門的分布有什么特點?
是不是,每個寶石收集之后,都要右轉?
找到這個關鍵點之后,我們的工作就簡單了。
執行的代碼如下:
for i in 1 ... 5 {
? ? moveForward()
? ? turnLeft()
? ? moveForward()
? ? moveForward()
? ? collectGem()
? ? turnRight()
}
是不是,一直到這里,for語句的方法都沒有變化。都要有一個你能設定的次數。
而被循環的指令都是你能控制的。可以變化的。
是不是很能感受循環的強大。
如果能用來寫字多好啊……
傳送門:
MacOS Playgrounds學習 學習編程一 前記--http://www.lxweimin.com/p/a0de277374a4
MacOS Playgrounds 學習編程一 第一關 發出命令--http://www.lxweimin.com/p/3c85397f1eae
MacOS Playgrounds 學習編程一 第二關 添加新命令--http://www.lxweimin.com/p/4efa5c18dc50
MacOS Playgrounds 學習編程一 第三關 切換開關--http://www.lxweimin.com/p/00556d6430bf
MacOS Playgrounds 學習編程一 第四關 傳送門練習--http://www.lxweimin.com/p/47bd57d0193f
MacOS Playgrounds 學習編程一 第五關 發現并修復程序錯誤--http://www.lxweimin.com/p/5bc9200edbbe
MacOS Playgrounds 學習編程一 第六關 消滅程序錯誤練習--http://www.lxweimin.com/p/f19bd2955ed8
MacOS Playgrounds 學習編程一 第七關 最短路線--http://www.lxweimin.com/p/1ef210253be5
MacOS Playgrounds 學習編程一 第八關 組合新行為--http://www.lxweimin.com/p/f548b1fd3134
MacOS Playgrounds 學習編程一 第九關 創建新函數--http://www.lxweimin.com/p/22ab39aaea97
MacOS Playgrounds 學習編程一 第十關 收集、切換、重復--http://www.lxweimin.com/p/e43d60f98bc7
MacOS Playgrounds 學習編程一 第十二關 嵌套模式--http://www.lxweimin.com/p/645f6716217c
MacOS Playgrounds 學習編程一 第十三關 嵌入式階梯--http://www.lxweimin.com/p/d87f9662601d
MacOS Playgrounds 學習編程一 第十四關 尋寶--http://www.lxweimin.com/p/18c73154e46b
MacOS Playgrounds 學習編程一 第十五關 使用循環--http://www.lxweimin.com/p/f7c0866930ec
MacOS Playgrounds 學習編程一 第十六關 循環每一側--http://www.lxweimin.com/p/94d75e9d5eab
MacOS Playgrounds 學習編程一 第十七關 行至邊緣再返回--http://www.lxweimin.com/p/cc7e8095bb9a
MacOS Playgrounds 學習編程一 第十八關 循環跳躍者--http://www.lxweimin.com/p/99618bef896e
MacOS Playgrounds 學習編程一 第十九關 拓展技能--http://www.lxweimin.com/p/a20810b11d6d
MacOS Playgrounds 學習編程一 第二十關 寶石農場--http://www.lxweimin.com/p/8c3808d1a646
MacOS Playgrounds 學習編程一 第二十一關 席卷四處--http://www.lxweimin.com/p/cc7f6a1c34e7
MacOS Playgrounds 學習編程一 第二十二關 檢查開關--http://www.lxweimin.com/p/e34fb0431b6e
MacOS Playgrounds 學習編程一 第二十三關 使用 else if--http://www.lxweimin.com/p/6414ef7692e2
MacOS Playgrounds 學習編程一 第二十四關 循環條件代碼--http://www.lxweimin.com/p/a657e47b851d
MacOS Playgrounds 學習編程一 第二十五關 滿足條件時向上爬--http://www.lxweimin.com/p/4a69a1c3435f
MacOS Playgrounds 學習編程一 第二十六關 定義更巧妙的函數--http://www.lxweimin.com/p/d61e03e095ae
MacOS Playgrounds 學習編程一 第二十七關 圍困其中--http://www.lxweimin.com/p/88442c7ce61b
MacOS Playgrounds 學習編程一 第二十八關 決策樹--http://www.lxweimin.com/p/0843bd9ae286
MacOS Playgrounds 學習編程一 第二十九關 使用“非”運算符--http://www.lxweimin.com/p/be8fa74b6c46
MacOS Playgrounds 學習編程一 第三十關 非之螺旋--http://www.lxweimin.com/p/f42905cbaed1
MacOS Playgrounds 學習編程一 第三十一關 檢查這個與那個--http://www.lxweimin.com/p/67b1c6e16b6a
MacOS Playgrounds 學習編程一 第三十二關 檢查這個或那個--http://www.lxweimin.com/p/d94a67728a93
MacOS Playgrounds 學習編程一 第三十三關 邏輯迷宮--http://www.lxweimin.com/p/62bbc0ce2490
MacOS Playgrounds 學習編程一 第三十四關 當……時運行代碼--http://www.lxweimin.com/p/9aa41733c6d0
MacOS Playgrounds 學習編程一 第三十五關 創建更巧妙的while循環--http://www.lxweimin.com/p/3fdfb33a443f
MacOS Playgrounds 學習編程一 第三十六關 正確選取工具--http://www.lxweimin.com/p/e5ed25be735e
MacOS Playgrounds 學習編程一 第三十七關 四乘以四--http://www.lxweimin.com/p/81ed2e6009d4
MacOS Playgrounds 學習編程一 第三十八關 轉身--http://www.lxweimin.com/p/a3c9bae7d6a2
MacOS Playgrounds 學習編程一 第三十九關 富饒之地--http://www.lxweimin.com/p/077743cdfcdd
MacOS Playgrounds 學習編程一 第四十關 套嵌循環--http://www.lxweimin.com/p/d8670c9e7962
MacOS Playgrounds 學習編程一 第四十一關 隨機矩形--http://www.lxweimin.com/p/61b916f61e37
MacOS Playgrounds 學習編程一 第四十二關 始終右轉--http://www.lxweimin.com/p/b7cf92fbfcaa
MacOS Playgrounds 學習編程一 第四十三關 右手定則--http://www.lxweimin.com/p/9ccd20151c96
MacOS Playgrounds 學習編程一 第四十四關 調整算法--http://www.lxweimin.com/p/10c2a0de990d
MacOS Playgrounds 學習編程一 第四十五關 征服迷宮--http://www.lxweimin.com/p/b4d731fe3639
MacOS Playgrounds 學習編程一 第四十六關 左轉還是右轉--http://www.lxweimin.com/p/cd7fa32316e5
MacOS Playgrounds 學習編程一 第四十七關 向左走,向右走--http://www.lxweimin.com/p/b9b1dc9c8f2e
MacOS Playgrounds學習 學習編程一 小結后記--http://www.lxweimin.com/p/8ad6485e447a