iOS移動應用程序開發(fā) | 第三講-集合與流程控制:Going Loopy...

第三次作業(yè)
作業(yè)一:完成Playgrounds App《學習編程2》1-3章
作業(yè)二:完成下面的練習題
1. Consider the following simple game. The game starts at level 1, and finishes at level 10. We've partially written a repeat-while loop to run the game. Fill in the two gaps.

2. The Chef, who is pretty grumpy at the best of times, wants to sort the restaurant's pizzas alphabetically using Swift (after all, it's in the name).

They're facing some issues, though. Can you help the chef sort their pizzas?
Consider the chef's list of pizzas, which they've stored as independently created String variables, and come up with:
(i) A better way to represent the list of pizzas, using one of the collection types that you've learned about.
(ii) A way to operate on your new pizza collection to sort the pizzas into alphabetical order and print them.
3. A Swift program is all scrambled up on the next page. Can you rearrange the code snippets to make a working program that produces the output below? The code uses concepts we've looked at in detail, as well as a few that we haven’t.


4. Your job is to take lines of code from the pool and place them into the blank lines in the Playground. You may not use the same line more than once, and you won’t need to use all the lines. Your goal is to make the code that will generate the output shown below, given the starting variables:


5. Each of the Swift code snippets on this page represents a complete Playground. Your job is to play Swift compiler, and determine whether each of these will run or not. If they will not compile, how would you fix them?


