Administrative things

Slides:



Advertisements
Similar presentations
Making Choices in C if/else statement logical operators break and continue statements switch statement the conditional operator.
Advertisements

Selection Statements Selects statements to execute based on the value of an expression The expression is sometimes called the controlling expression Selection.
Copyright © 2009 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Java Software Solutions Foundations of Program Design Sixth Edition by Lewis.
1 Lecture 5  More flow control structures  for  do  continue  break  switch  Structured programming  Common programming errors and tips  Readings:
Algorithms and Computing Lecture 3 Control Statements By Dr. M. Tahir Khaleeq.
Lecture 10: Reviews. Control Structures All C programs written in term of 3 control structures Sequence structures Programs executed sequentially by default.
1 計算機程式設計 Introduction to Computer Programming Lecture01: Introduction and Hello World 9/10/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction.
/* C Programming for the Absolute Beginner */ // by Michael Vine #include main() { printf(“\nC you later\n”); system(“pause”); }
Copyright © 2010 Pearson Education, Inc. Publishing as Pearson Addison-Wesley Chapter 4: Making Decisions.
Week 4 Program Control Structure
1 Lecture03: Control Flow 9/24/2012 Slides modified from Yin Lou, Cornell CS2022: Introduction to C.
Instructor: Alexander Stoytchev CprE 185: Intro to Problem Solving (using C)
Control structures in C by Dr P.Padmanabham Professor (CSE)&Director Bharat Institute of Engineering &Technology Hyderabad Mobile
Lecture 6 – Selection FTMK, UTeM – Sem /2014.
CS113 Introduction to C Instructor: Ioannis A. Vetsikas Lecture 2 : August 28 webpage:
Lecture2.
CSE1301 Sem Selection Lecture 25 Lecture 9: Selection.
Chapter 4 – C Program Control
Decision Making in C.
EKT120 COMPUTER PROGRAMMING
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
ECE Application Programming
Week 3 - Friday CS222.
Chapter 2 - Introduction to C Programming
Lecture 7: Repeating a Known Number of Times
Chapter 4: Making Decisions.
EKT150 INTRODUCTION TO COMPUTER PROGRAMMING
Chapter 2 Overview of C.
ICS103 Programming in C Lecture 3: Introduction to C (2)
Chapter 4: Making Decisions.
Chapter 2 - Introduction to C Programming
Chapter 4: Making Decisions.
Conditionals, Loops, and Other Kinds of Statements
Introduction to C Programming
Administrative things
Chapter 13 Control Structures
Introduction to Programming
Lecture 2: Logical Problems with Choices
Chapter 13 Control Structures
Chapter 2 - Introduction to C Programming
Chapter 2 - Introduction to C Programming
CS1100 Computational Engineering
Chapter 2 - Introduction to C Programming
Chapter 4 - Program Control
Introduction to C Programming
Exam 1 Date: Feb. 2nd, 2015 during class time (50 minutes) Coverage
CSC215 Lecture Flow Control.
Conditions and Boolean Expressions
CSC215 Lecture Control Flow.
Program Breakdown, Variables, Types, Control Flow, and Input/Output
Chapter 2 - Introduction to C Programming
Lecture3.
Relational, Logical, and Equality Operators
Conversion Check your class notes and given examples at class.
The Java switch Statement
CprE 185: Intro to Problem Solving (using C)
Week 3 – Program Control Structure
Chapter 2 - Introduction to C Programming
Introduction to Computing Lecture 04: Booleans & Selection
EECE.2160 ECE Application Programming
ECE 103 Engineering Programming Chapter 18 Iteration
More Loops Topics Relational Operators Logical Operators for Loops.
CSCE 206 Lab Structured Programming in C
CSC215 Lecture Control Flow.
Introduction to C Programming
CprE 185: Intro to Problem Solving (using C)
Administrative things
Administrative things
Chapter 13 Control Structures
Presentation transcript:

Lecture03: Control Flow 3/4/2013 Slides modified from Yin Lou, Cornell CS2022: Introduction to C

Administrative things Any problem with submitting assignment #1? Assignment #2 is on the course webpage due next week. Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

Review from Last Week Variable declaration C Punctuations Type, variable name C Punctuations ; , “ { } ( % # printf() : write to the screen printf(format string, arg1, arg2, …) What is a format string? Placeholder tags whose values are substitute by args. What are placeholder tags? scanf() : read from the screen (user) scanf(format string, &arg1, &arg2, …) Store values into locations pointed by args Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

main.c: Variables & Punctuations #include <stdio.h> int main() { int a, b, c; a = 10; b = 20; c = a * b; printf("a = %d b = %d c = %d\n", a, b, c); return 0; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

More on printf() printf(format string, val1, val2); Example format string can include placeholders that specify how the arguments val1, val2, etc. should be formatted %c : format as a character %d : format as an integer %f : format as a floating-point number %% : print a % character Example double f = 0.95; printf("f = %f%%\n", f * 100); Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

scanf() #include <stdio.h> int main() { int i; double f; scanf("%d", &i); scanf("%lf", &f); printf("Integer: %d Float: %.2f\n", i, f); return 0; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

New Stuff: Control Flow Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

Statement <statement> := <expression>; x = 0; ++i; // comments go here: i = i + 1; printf("%d", x); /* another way to write comments */ Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

Blocks <block> := { <statements> } x = 0; ++i; printf("%d", x); } A block is syntactically equivalent to a single statement. if, else, while, for Variables can be declared inside any block. There is no semicolon after the right brace that ends a block. Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

Example int x = 0; { int x = 5; printf("Inside: x = %d\n", x); } printf("Outside: x = %d\n", x); Inside: x = 5 Outside: x = 0 Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

if Statement if (<condition>) <statement> // single statement if (2 < 5) printf("2 is less than 5.\n"); // block { printf("I'll always print this line.\n"); printf("because 2 is always less than 5!\n"); } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

if-else Statement if (<condition>) <statement1> else <statement2> if (x < 0) { printf("%d is negative.\n", x); } else printf("%d is non-negative.\n", x); Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

else-if Statement if (a < 5) printf("a < 5\n"); else { if (a < 8) printf("5 <= a < 8\n"); printf("a >= 8\n"); } if (a < 5) printf("a < 5\n"); else if (a < 8) printf("5 <= a < 8\n"); else printf("a >= 8\n"); Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

if-else Statement Pitfalls if (a > 70) if (a > 80) printf("grade = B\n"); else printf("grade < B\n"); printf("Fail.\n"); printf("Done.\n"); if (a > 70) { if (a > 80) printf("grade = B\n"); } else printf("grade < B\n"); printf("Fail.\n"); printf("Done.\n"); Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

Relational Operators C has the following relational operators a == b true iff a equals b a != b true iff a does not equal b a < b true iff a is less than b a > b true iff a is greater than b a <= b true iff a is less than or equal to b a >= b true iff a is greater than or equal to b a && b true iff a is true and b is true a || b true iff a is true or b is true !a true iff a is false Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

Booleans in C C DOES NOT have a boolean type. boolean means true or false. Instead, conditional operators evaluate to integers (int) 0 indicates false. Non-zero value is true. if (<condition>) checks whether the condition is non-zero. Programmer must be very careful to this point! Example if (3) printf("True.\n"); if (!3) // unreachable code if (a = 5) // always true, potential bug (a == 5) int a = (5 == 5); // a = 1 Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

In-Class Exercise #1 Write a program that reads a number grade (0-100) and converts it into a letter grade (ABCF): A:80-100, B:70-79, C:60-69, and F<60. Your program should have the following input & output: Input a number grade> 80 Letter grade: A Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

Conditional expressions < condition> ? <expression1> : <expression2> char grade; grade = (score >= 70 ? 'S' : 'U'); printf("You have %d item%s.\n", n, n == 1 ? "" : "s"); Conditional expression often leads to concise code. Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

switch Statement A common form of if statement if (x == a) statement1; else if (x == b) statement2; ... else statement0; switch statement switch (x) { case a: statement1; break; case b: statement2; break; ... default: statement0; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

More on switch Statement Fall-through property int month = 2; switch (month) { case 1: printf("Jan.\n"); break; case 2: printf("Feb.\n"); case 3: printf("Mar.\n"); default: printf("Another month.\n"); } Feb. Mar. Another month. Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

More on switch Statement Fall-through property int month = 2; int days; switch (month) { case 2: days = 28; break; case 9: case 4: case 6: case 11: days = 30; default: days = 31; } It's always recommended to have default, though it's optional. if (month == 2) { days = 28; } else if (month == 9)) || (month == 6) || (month == 11)) days = 30; Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

In-Class Exercise #2 Write a program that reads a month (1-12) and converts it into a season: Spring:3-5, Summer:6-8; Fall:9-11 Winter:12-2. Use the switch statement. Your program should have the following input & output: Input a month(1-12)> 1 Season: Winter Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

while Loop while (<condition>) <statement> If the condition is initially false, the statement is never executed. do <statement> while (<condition>); The statement is executed at least once. Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

while Loop example #include <stdio.h> int main() { int i = 1; while (i < 10) printf("%d ", i); i++; // i = i +1; } return 0; i = 1; Is i < 10? Yes, continue i ++; i is now 2; Is i < 10?; Yes, continue i++; i is now 3; … i++; i is now 10; Is i < 10?; No, exit the loop Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

do Loop example #include <stdio.h> int main() { int i = 1; do printf("%d ", i); i++; } while (i < 10); } #include <stdio.h> int main() { int i = 1; while (i < 10) printf("%d ", i); i++; // i = i +1; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

for Loop for (<exp1>; <exp2>; <exp3>) <statement> exp1; while (exp2) { statement exp3; } for (i = 0; i < n; i++) // do something Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

for Loop example #include <stdio.h> int main() { int i; for (i=1; i<10; i++) printf("%d ", i); } #include <stdio.h> int main() { int i = 1; while (i < 10) printf("%d ", i); i++; } #include <stdio.h> int main() { int i = 1; do printf("%d ", i); i++; } while (i < 10); } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

Infinite Loop while (1) { // do something } for (;;) { // do something } Both are okay, but for may lead to fewer machine code on some platform, which means it is slightly more efficient. Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

break exit the loop #include <stdio.h> int main() { int n = 10; while (1) if (!n) break; // exit the loop } printf("%d\n", n); --n; // similar to n--; Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

continue jump to before the end of loop #include <stdio.h> int main() { int i; for (i = 0; i < 10; ++i) if (i == 5) continue; /* jump to before the end of the loop */ } printf("%d\n", i); /* continue jumps to here */ Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

Common Pitfalls Always use {} Put literals on the left int i; for (i = 0; i < 10; ++i); printf("%d\n", i); Put literals on the left int n = 10; while (n = 1) { printf("%d\n", n); --n; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

How to Avoid Bugs? Always use {} Put literals on the left int i; for (i = 0; i < 10; ++i) { printf("%d\n", i); } Put literals on the left int n = 10; while (1 == n) // 1 = n, likely a bug { printf("%d\n", n); --n; } Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

Review for Today if, else-if < condition> ? <expression1> : <expression2> switch, case, default, break for (<exp1>; <exp2>; <exp3>) <statement> while (<condition>) <statement> do <statement> while (<condition>); break, continue Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?

In-Class Exercise #3 Write a program that print all Fibonacci numbers smaller than 100. Fibonacci numbers are numbers in the following integer sequence: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, … Your program should output exactly the following line. Note that there should not be a “,” after the last number. Fib: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89 Software infrastructure: support integration between physical space and virtual computing space, adapting to different smart environment, etc. Sensors: acquire user context such as techniques to estimate location from 802.11, etc. Context-aware applications: how can we use the context information to make application or everyday objects intelligent Security and privacy: user context information (where you are) should be protected. Human experience: user experience in ubicomp environment – how to evaluate it quantitatively or qualitatively? Ubiquitous data access: access information from any devices in any modalities from any networks Coping with uncertainty: sensors may have errors (GPS). Social computing: ubicomp is used in everyday physical / virtual activities. It will affect your social activities. How can we use it to improve your social lives?