Presentation is loading. Please wait.

Presentation is loading. Please wait.

反覆迴圈、陣列、副程式 靜宜大學資管系 楊子青

Similar presentations


Presentation on theme: "反覆迴圈、陣列、副程式 靜宜大學資管系 楊子青"— Presentation transcript:

1 反覆迴圈、陣列、副程式 靜宜大學資管系 楊子青
反覆迴圈、陣列、副程式 靜宜大學資管系 楊子青

2 1. 兩種反覆迴圈 (1) The foreach block applies a set of functions to each element of a list.

3 Two blocks for repeating operations
(2) While is more general: With while, the inner blocks are performed continuously while a certain condition is true. After the blocks within the while are executed, control loops back up and the test condition is tried again. Only when the test evaluates to false does the while block complete.

4 開新專案Compute,計算1+2+…+10

5 (1) For迴圈,計算1+2+…+10程式碼 試試看區域變數

6 區域變數若超出範圍,則從記憶體移除,因此無法再使用

7 (2) While迴圈,計算1+2+…+10程式碼 練習:計算 1*2*3*…*N

8 2. 陣列 Complex, interrelated items that must be organized Lists
Many apps process lists of data. For example: Facebook processes your list of friends. A quiz app works with a list of questions and answers. Lists static lists (in which the data doesn’t change) dynamic lists (in which the data is user-generated).

9 Compute專案,新增讀取學院按鈕

10 Compute專案,查詢本校學院程式碼 靜態陣列 動態增加陣列元素

11 ListPicker component displays the items of a list and allows the user to choose one.

12 Compute專案,新增ListPicker元件

13 BeforePicking設定陣列元素

14 AfterPicking顯示使用者選擇之項目

15 3. 副程式 To define higher-level procedure blocks
is the key to engineering large, maintainable software and solving complex problems without being constantly overwhelmed by all of the details. let you encapsulate code blocks and give those blocks a name. While you program the procedure, you focus solely on the details of those blocks. But in programming the rest of the app, you now have an abstraction—a name—that you can refer to at a high level.

16 (1) Defining a Procedure
drag out either a to procedure block or a to procedure with result block. Use the latter if your procedure should calculate some value and return it

17 (2) Adding Parameters to Procedure

18 (3) Returning Values from a Procedure

19 (4) Calling a Procedure

20 Compute專案,改用procedure


Download ppt "反覆迴圈、陣列、副程式 靜宜大學資管系 楊子青"

Similar presentations


Ads by Google