Download presentation
Presentation is loading. Please wait.
Published byBertram Allison Modified over 9 years ago
1
introduction to touchdevelop statements overview Disclaimer: This document is provided “as-is”. Information and views expressed in this document, including URL and other Internet Web site references, may change without notice. You bear the risk of using it. This document does not provide you with any legal rights to any intellectual property in any Microsoft product. You may copy and use this document for your internal, reference purposes. © 2012 Microsoft Corporation. All rights reserved. Microsoft, Windows, and Windows Live are trademarks of the Microsoft group of companies. All other trademarks are property of their respective owners.
2
introduction to touchdevelop statements o expression statement o if … then … else o for each [var] in … where … do … o for 0 ≤ [var] < … do … o while … do o // comments o do nothing
3
introduction to touchdevelop adding o tap one of the + in the statement menu o tap intended statement button
4
introduction to touchdevelop editing o first, enter condition/bound/ collection o tap the hardware back button when done
5
introduction to touchdevelop editing o to modify condition/bound/collection, select entire expression o to modify body, select statement in body
6
introduction to touchdevelop expression statement o any expression is a statement o unassigned expression results are simply forgotten
7
introduction to touchdevelop if … then … else o empty else-branch is shown in compact form, but cannot be removed
8
introduction to touchdevelop for each [var] in … where … do … o iterates over a collection actually equivalent to a loop from i :=0 to (collection→count-1), assigning collection→at(i ) to loop variable [var] in each iteration o iteration variable is automatically synthesized to rename it, use it in the body, tap on it, and rename o use ‘where’ clause to filter, if desired equivalent to ‘if’, but more efficient o example: for each song in media→ songs where song→duration > 180 do song→post to wall
9
introduction to touchdevelop demo / exercise ► let’s write this script: for each song in media→ songs where song→duration > 180 do song→post to wall
10
introduction to touchdevelop for 0 ≤ [var] < … do … o iterates from 0 (includes) to an upper bound (exclusive) o iteration variable is automatically synthesized to rename it, use it in the body, tap on it, and rename o example: for 0 ≤ i < 4 do i→post to wall prints 3 2 1 0
11
introduction to touchdevelop for 0 ≤ [var] < … do … o surprised by the ordering on the wall? try this: for 0 ≤ i < 4 do i→post to wall time→sleep(1)
12
introduction to touchdevelop while … do … o executes loop body while condition is true o example: i := 0 while i < 4 do i →post to wall i := i + 1 prints 3 2 1 0
13
introduction to touchdevelop demo / exercise ► let’s write this script: i := 0 while i < 4 do i →post to wall i := i + 1
14
introduction to touchdevelop scope o in the app, scope is indicated by indentation (and gray lines) o to add a statement in a particular scope, select an existing statement in that scope, and tap +
15
introduction to touchdevelop // comments o comments do nothing o (unlike many other language, comments are maintained in the “abstract syntax tree” to play nice with the editor)
16
introduction to touchdevelop do nothing o place holder statement
17
introduction to touchdevelop title o item 1 o item 2 song→post to wall ☀ anecdote ☁ http://touchdevelop.com/velk (link to sample)http://touchdevelop.com/velk ► an exercise ✿ a reference
Similar presentations
© 2024 SlidePlayer.com. Inc.
All rights reserved.