2018-02-16から1日間の記事一覧
//ランダムな四角形@コードを学ぼう1 while !isOnClosedSwitch { while !isBlocked { moveForward() } turnRight() } toggleSwitch()
//ループをネストする@コードを学ぼう1 while !isBlocked { while !isOnGem { moveForward() } turnLeft() collectGem() }
//方法はたくさん@コードを学ぼう1 func a() { while !isBlocked { moveForward() if isOnGem || isOnClosedSwitch { collectGem() toggleSwitch() } } } a() turnRight() moveForward() turnRight() a() turnLeft() moveForward() turnLeft() a()
//回る@コードを学ぼう1 func s() { moveForward() collectGem() turnLeft() moveForward() collectGem() turnLeft() moveForward() turnRight() } for i in 1 ... 4 { s() }
//2つのループ@コードを学ぼう1 for i in 1 ... 4 { for i in 1 ... 3 { moveForward() } if isOnClosedSwitch { toggleSwitch() } turnRight() }
//正しいループを使う@コードを学ぼう1 func turnAndCollectGem() { moveForward() turnLeft() moveForward() collectGem() turnRight() } while !isBlocked { turnAndCollectGem() }
//whileループをじょうずに使う@コードを学ぼう1 while !isBlocked { if isOnClosedSwitch { toggleSwitch() } moveForward() }
//条件を決めてコードをループする@コードを学ぼう1 while isOnClosedSwitch { toggleSwitch() moveForward() }
//論理の迷宮@コードを学ぼう1 for i in 1 ... 8 { moveForward() if isOnGem && isOnClosedSwitch { turnRight() moveForward() moveForward() collectGem() turnLeft() turnLeft() moveForward() moveForward() turnRight() toggleSwitch() collectGem() …
//一方でも正しければ合格@コードを学ぼう1 for i in 1 ... 12 { if isBlockedLeft || isBlocked { turnRight() moveForward() } moveForward() if isOnGem { collectGem() } } youtu.be