if then else - TouchDevelop

Download Report

Transcript if then else - TouchDevelop

if then else
conditional statement
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.
introduction to touchdevelop
if .. then ..
o
“if condition is true then do stuff”
if balance < 0 then
social→send email(“me”, “empty!”, “”)
o
tell the phone to run code only if the
condition is met
introduction to touchdevelop
if .. then .. else
..
o
“if condition is true then do stuff
else do other stuff”
if balance < 0 then
social→send email(“me”, “empty!”, “”)
else
“enough balance!” →post to wall
☁ http://touchdevelop.com/pddx
introduction to touchdevelop
editing
o
tap + in the statement
menu
o
tap the if button
introduction to touchdevelop
editing
o
edit the condition
o
tap the hardware back
button when done
introduction to touchdevelop
exercises
►”play a random song; on shake, toggle the player
between resume and pause”
►”ask the user a question (‘1+2=?’); if false, vibrate, if true
play a victory song”
•
wall→ask number to ask a number to the user
►”ask the user a duration in seconds; if the duration is
between 0 and 5, vibrate for that amount of seconds”
☀ you can add an if statement inside of then or else.
introduction to touchdevelop
true/false maths
o
known as Boolean logic
o
a Boolean condition may be true or false
or
true
true true
false true
not
false
true
false
and true false
true true false
false false false
true false
false true
introduction to touchdevelop
exercises
► true and false = ?
► false or true = ?
► not true = ?
► true or not true = ?
► not true and not false = ?
► not true or not false= ?
in doubt, try it out on the phone…
introduction to touchdevelop