REVIEW. while (condition) { <body> for (<init> ; <condition> ; <increment>) { } if (condition) { <command> } else { <command> }

Size: px
Start display at page:

Download "REVIEW. while (condition) { <body> for (<init> ; <condition> ; <increment>) { } if (condition) { <command> } else { <command> }"

Transcription

1 REVIEW while (condition) { } <body> for (<init> ; <condition> ; <increment>) { } if (condition) { <command> } else { <command> }

2 CHALLENGE PROBLEMS (from lecture 4) // sum up all elements of an array A = [1,2,3,4,5,6,7,8,9,10];

3 CHALLENGE PROBLEMS (from lecture 4) // sum up all elements of an array A = [1,2,3,4,5,6,7,8,9,10]; for (var i=0; i<a.length; i++) { }

4 CHALLENGE PROBLEMS (from lecture 4) // sum up all elements of an array A = [1,2,3,4,5,6,7,8,9,10]; for (var i=0; i<a.length; i++) { } s = s + A[i];

5 CHALLENGE PROBLEMS (from lecture 4) // sum up all elements of an array A = [1,2,3,4,5,6,7,8,9,10]; s = 0; for (var i=0; i<a.length; i++) { s = s + A[i]; }

6 CHALLENGE PROBLEMS (from lecture 4) // sum up all elements of an array A = [1,2,3,4,5,6,7,8,9,10]; s = 0; for (var i=0; i<a.length; i++) { s = s + A[i]; } print( s );

7 CHALLENGE PROBLEMS (from lecture 4) // reverse order of items in array A = [1,2,3,4,5,6,7,8,9,10];

8 CHALLENGE PROBLEMS (from lecture 4) // reverse order of items in array A = [1,2,3,4,5,6,7,8,9,10];

9 CHALLENGE PROBLEMS (from lecture 4) // reverse order of items in array A = [1,2,3,4,5,6,7,8,9,10];

10 CHALLENGE PROBLEMS (from lecture 4) // reverse order of items in array A = [1,2,3,4,5,6,7,8,9,10];

11 CHALLENGE PROBLEMS (from lecture 4) // reverse order of items in array A = [1,2,3,4,5,6,7,8,9,10];

12 CHALLENGE PROBLEMS (from lecture 4) // reverse order of items in array A = [1,2,3,4,5,6,7,8,9,10];

13 CHALLENGE PROBLEMS (from lecture 4) // reverse order of items in array A = [1,2,3,4,5,6,7,8,9,10]; for (var i=0; i<a.length; i++) { j =??? }

14 CHALLENGE PROBLEMS (from lecture 4) // reverse order of items in array A = [1,2,3,4,5,6,7,8,9,10]; for (var i=0; i<a.length; i++) { j = A.length-i-1; }

15 CHALLENGE PROBLEMS (from lecture 4) // reverse order of items in array A = [1,2,3,4,5,6,7,8,9,10]; for (var i=0; i<a.length; i++) { j = A.length-i-1; A[i] = A[j]; A[j] = A[i]; }

16 CHALLENGE PROBLEMS (from lecture 4) // reverse order of items in array A = [1,2,3,4,5,6,7,8,9,10]; for (var i=0; i<a.length; i++) { j = A.length-i-1; temp = A[i]; A[i] = A[j]; A[j] = temp; } print( A );

17 CHALLENGE PROBLEMS (from lecture 4) // reverse order of items in array A = [1,2,3,4,5,6,7,8,9,10]; for (var i=0; i<a.length; i++) { j = A.length-i-1; temp = A[i]; A[i] = A[j]; A[j] = temp; } print( A ); output = [1,2,3,4,5,6,7,8,9,10]

18 CHALLENGE PROBLEMS (from lecture 4) // reverse order of items in array A = [1,2,3,4,5,6,7,8,9,10]; for (var i=0; i<a.length/2; i++) { j = A.length-i-1; temp = A[i]; A[i] = A[j]; A[j] = temp; } print( A );

19 Function parameters: we pass values into a function

20 Function parameters: we pass values into a function var <name> = function() { <command 1>; <command 2>; <command 3>;

21 Function parameters: we pass values into a function // Draw a square with upper left x, y and side length s var square = function(x, y, s) { line(x, y, x+s, y); line(x+s, y, x+s, y+s); line(x+s, y+s, x, y+s); line(x, y+s, x, y); square(10, 20, 20);

22 Function parameters: we pass values into a function // Draw a square with upper left x, y and side length s var square = function(x, y, s) { line(x, y, x+s, y); line(x+s, y, x+s, y+s); line(x+s, y+s, x, y+s); line(x, y+s, x, y); square(10, 20, 20);

23 Function parameters: we pass values into a function // Draw a square with upper left x, y and side length s var square = function(x, y, s) { line(x, y, x+s, y); line(x+s, y, x+s, y+s); line(x+s, y+s, x, y+s); line(x, y+s, x, y); square(10, 20, 20);

24 Function parameters: we pass values into a function // Draw a square with upper left x, y and side length s var square = function(x, y, s) { line(x, y, x+s, y); line(x+s, y, x+s, y+s); line(x+s, y+s, x, y+s); line(x, y+s, x, y); square(10, 20, 20);

25 Function parameters: we pass values into a function // Draw a square with upper left x, y and side length s var square = function(x, y, s) { line(x, y, x+s, y); line(x+s, y, x+s, y+s); line(x+s, y+s, x, y+s); line(x, y+s, x, y); square(10, 20, 20); variables only have scope inside of function

26 var drawtree = function() { var x = 200; var y = 200; nostroke(); fill(100, 50, 0); // brown rect(x-5, y-50, 10, 50); stroke(0, 140, 0); fill(0, 195, 0); // green ellipse(x+0, y-50, 40, 40); drawtree();

27 var drawtree = function() { var x = 200; var y = 200; nostroke(); fill(100, 50, 0); // brown rect(x-5, y-50, 10, 50); stroke(0, 140, 0); fill(0, 195, 0); // green ellipse(x+0, y-50, 40, 40); drawtree();

28 var drawtree = function() { var x = 200; var y = 200; nostroke(); fill(100, 50, 0); // brown rect(x-5, y-50, 10, 50); stroke(0, 140, 0); fill(0, 195, 0); // green ellipse(x+0, y-50, 40, 40); drawtree();

29 EXERCISE Write a function drawtree that allows a tree to be drawn so that the bottom center of the tree is positioned at x and y coordinates specified as function parameters. Test your code by calling the function a few times. nostroke(); fill(100, 50, 0); // brown rect(195, 150, 10, 50); stroke(0, 140, 0); fill(0, 195, 0); // green ellipse(200, 150, 40, 40);

30 var drawtree = function(x, y) { nostroke(); fill(100, 50, 0); // brown rect(x-50, y-50, 10, 50); stroke(0, 140, 0); fill(0, 195, 0); // green ellipse(x+0, y-50, 40, 40); drawtree(100, 400); drawtree(130, 400); drawtree(300, 400);

31 var drawtree = function(x, y) { nostroke(); fill(100, 50, 0); // brown rect(x-50, y-50, 10, 50); stroke(0, 140, 0); fill(0, 195, 0); // green ellipse(x+0, y-50, 40, 40); drawtree(100, 400); drawtree(130, 400); drawtree(300, 400); variables only have scope inside of function

32 Function parameters: we return values from a function var x = 1 + 2; print( x );

33 Function parameters: we return values from a function addition is a function that returns the sum var x = 1 + 2; print( x );

34 Function parameters: we return values from a function var x = Math.sqrt(25); print( x );

35 Function parameters: we return values from a function Math is a Javascript object with many functions. var x = Math.sqrt(25); print( x );

36 Function parameters: we return values from a function sqrt takes a parameter as input var x = Math.sqrt(25); print( x );

37 Function parameters: we return values from a function and returns a value var x = Math.sqrt(25); print( x );

38 Function parameters: we return values from a function print( Math.sqrt(25) );

39 Function parameters: we return values from a function print( Math.sqrt(25) ); Evaluate function.

40 Function parameters: we return values from a function print( Math.sqrt(25) ); Evaluate function. Value returned from sqrt is parameter to function print

41 Function parameters: we return values from a function // print integer factors of 100 for( var i=1; i<???; i++ ) { if( 100 % i === 0 ) { print( i ); } }

42 Function parameters: we return values from a function // print integer factors of 100 for( var i=1; i<10; i++ ) { if( 100 % i === 0 ) { print( i ); } }

43 Function parameters: we return values from a function // print integer factors of 100 for( var i=1; i<math.sqrt(100); i++ ) { if( 100 % i === 0 ) { print( i ); } }

44 Function parameters: we return values from a function // print integer factors var x = 100; for( var i=1; i<math.sqrt(x); i++ ) { if( x % i === 0 ) { print( i ); } }

45 Math Math.sqrt(100); // returns 10 Math.round(4.4); // returns 4 Math.round(4.7); // returns 5 Math.pow(8,2); // returns 64 Math.abs(-4.7); // returns 4.7 Math.cos(90 * Math.PI/180); // returns 0 Math.min(0, 100, -6, 24); // returns -6 Math.max(0, 100, -6, 24); // returns 100 Math.random(); // returns a random number [0,1]

46 Define functions that return values var computesqrt = function(x) { print( Math.sqrt(x) ); computesqrt(100);

47 Define functions that return values var computesqrt = function(x) { return( Math.sqrt(x) ); print( computesqrt(100) );

48 Define functions that return values var computesqrt = function(x) { return( Math.sqrt(x) ); print( computesqrt(100) ); return!= print

49 Define functions that return values var computesqrt = function(x) { return( Math.sqrt(x) ); print( computesqrt(100) );

50 Define functions that return values var computesqrt = function(x) { return( Math.sqrt(x) ); print( computesqrt(100) );

51 Define functions that return values var computesqrt = function(x) { return( Math.sqrt(x) ); var x = computesqrt(100);

52 Define functions that return values var computesqrt = function(x) { return( Math.sqrt(x) ); computesqrt(100); output?

53 Define functions that return values var computesqrt = function(x) { return( Math.sqrt(x) ); print( hello ); computesqrt(100); output?

54 Define functions that return values var number = 39; if( number % 2 === 0 ) { print( even ); } else { print( odd ); }

55 EXERCISE Write a function that returns even if the parameter passed to it is even and odd otherwise. var number = 39; if( number % 2 === 0 ) { print( "even" ); } else { print( "odd" ); }

56 var iseven = function( number ) { if( number % 2 === 0 ) { return( "even" ); } else { return( "odd" ); }

57 var iseven = function( number ) { if( number % 2 === 0 ) { return( "even" ); } else { return( "odd" ); } print( iseven( 39 ) ); print( iseven( 40 ) );

58 var iseven = function( number ) { if( number % 2 === 0 ) { return( "even" ); } else { return( "odd" ); } var x = iseven( 39 );

59 var iseven = function( number ) { if( number % 2 === 0 ) { return( true ); } else { return( false ); } print( iseven( 39 ) );

60 var iseven = function( number ) { if( number % 2 === 0 ) { return( true ); } else { return( false ); } print( iseven( 39 ) ); var iseven = function( number ) { return( number % 2 === 0 ); print( iseven( 39 ) );

61 var iseven = function( number ) { if( number % 2 === 0 ) { return( true ); } else { return( false ); } print( iseven( 39 ) ); var iseven = function( number ) { return( number % 2 === 0 ); print( iseven( 39 ) );

62 Scope var somefunction = function() { var x = 4; print( x ); somefunction(); print( x );

63 Scope var somefunction = function() { var x = 4; print( x ); somefunction(); print( x );

64 Scope var somefunction = function() { var x = 4; print( x ); somefunction(); print( x );

65 Scope var somefunction = function() { var x = 4; print( x ); somefunction(); print( x );

66 Scope var somefunction = function() { var x = 4; print( x ); somefunction(); print( x );

67 Scope var somefunction = function() { var x = 4; the scope of x is in the print( x ); body of this function somefunction(); print( x ); error

68 Scope var somefunction = function() { var x = 4; print( x ); var x = 10; somefunction(); print( x ); what is the output?

69 Scope var somefunction = function() { var x = 4; print( x ); var x = 10; somefunction(); print( x ); global variable: (generally) bad

70 Frames var somefunction = function() { var x = 4; print( x ); var anotherfunction = function(y) { return( Math.pow(2,y) ); var z = 10; somefunction(); z = anotherfunction(8); print( z );

71 Frames var somefunction = function() { var x = 4; print( x ); var anotherfunction = function(y) { return( Math.pow(2,y) ); var z = 10; somefunction(); z = anotherfunction(8); print( z ); z = 10 global frame

72 Frames var somefunction = function() { var x = 4; print( x ); x = 4 frame var anotherfunction = function(y) { return( Math.pow(2,y) ); var z = 10; somefunction(); z = anotherfunction(8); print( z ); z = 10 global frame

73 Frames var somefunction = function() { var x = 4; print( x ); var anotherfunction = function(y) { return( Math.pow(2,y) ); var z = 10; somefunction(); z = anotherfunction(8); print( z ); frame z = 10 global frame

74 Frames var somefunction = function() { var x = 4; print( x ); var anotherfunction = function(y) { return( Math.pow(2,y) ); var z = 10; somefunction(); z = anotherfunction(8); print( z ); z = 256 global frame

75 Frames var somefunction = function() { var x = 4; return( x ); y = somefunction(); print( y ); print( x );

76 Frames var somefunction = function() { var x = 4; return( x ); y = somefunction(); print( y ); print( x );???

77 Frames var somefunction = function() { var x = 4; return( x ); y = somefunction(); print( y ); print( x ); 4

78 Frames var somefunction = function() { var x = 4; return( x ); y = somefunction(); print( y ); print( x );???

79 Frames var somefunction = function() { var x = 4; return( x ); y = somefunction(); print( y ); print( x ); error

80 Frames var somefunction = function() { var x = 4; return( x ); var x = 5; print( somefunction() ); print( x );

81 Frames var somefunction = function() { var x = 4; return( x ); var x = 5; print( somefunction() ); print( x ); global frame

82 Frames var somefunction = function() { var x = 4; return( x ); local frame var x = 5; print( somefunction() ); print( x );

83 Frames var somefunction = function() { var x = 4; return( x ); var x = 5; print( somefunction() ); print( x );???

84 Frames var somefunction = function() { var x = 4; return( x ); var x = 5; print( somefunction() ); print( x ); 4

85 Frames var somefunction = function() { var x = 4; return( x ); var x = 5; print( somefunction() ); print( x );???

86 Frames var somefunction = function() { var x = 4; return( x ); var x = 5; print( somefunction() ); print( x ); 5

87 Frames var somefunction = function() { return( x ); var x = 5; print( somefunction() ); print( x );

88 Frames var somefunction = function() { return( x ); var x = 5; print( somefunction() ); print( x );???

89 Frames var somefunction = function() { return( x ); var x = 5; print( somefunction() ); print( x ); 5

90 Frames var somefunction = function() { return( x ); var x = 5; print( somefunction() ); print( x );???

91 Frames var somefunction = function() { return( x ); var x = 5; print( somefunction() ); print( x ); 5

92 Callbacks var surprise = function() { print( "surprise" ); surprise();

93 Callbacks var surprise = function() { print( "surprise" ); settimeout( surprise, 5000 );

94 Callbacks var surprise = function() { print( "surprise" ); settimeout( surprise, 5000 ); built-in Javascript function

95 Callbacks var surprise = function() { print( "surprise" ); settimeout( surprise, 5000 ); a function

96 Callbacks var surprise = function() { print( "surprise" ); settimeout( surprise, 5000 ); call function after this many milliseconds (1000 ms = 1 s)

97 Callbacks var countdown = function() { while( counter > 0 ){ print( counter ); counter = counter - 1; } print( "Blast off!" ); print( "prepare for countdown " ); var counter = 10; countdown();

98 Callbacks var countdown = function() { while( counter > 0 ){ print( counter ); counter = counter - 1; } print( "Blast off!" ); print( "prepare for countdown " ); var counter = 10; countdown(); prepare for countdown Blast off!

99 Callbacks var countdown = function() { while( counter > 0 ){ print( counter ); counter = counter - 1; } print( "Blast off!" ); print( "prepare for countdown " ); var counter = 10; settimeout( countdown, 1000 );

100 Callbacks var countdown = function() { while( counter > 0 ){ print( counter ); counter = counter - 1; } print( "Blast off!" ); prepare for countdown print( "prepare for countdown " ); var counter = 10; settimeout( countdown, 1000 );

101 Callbacks var countdown = function() { while( counter > 0 ){ print( counter ); counter = counter - 1; } print( "Blast off!" ); print( "prepare for countdown " ); var counter = 10; settimeout( countdown, 1000 ); prepare for countdown Blast off!

102 Callbacks var countdown = function() { if( counter > 0 ){ print( counter ); counter = counter - 1; } else { print( "Blast off!" ); } print( "prepare for countdown " ); var counter = 10; settimeout( countdown, 1000 );

103 Callbacks var countdown = function() { if( counter > 0 ){ print( counter ); counter = counter - 1; } else { print( "Blast off!" ); } prepare for countdown print( "prepare for countdown " ); var counter = 10; settimeout( countdown, 1000 );

104 Callbacks var countdown = function() { if( counter > 0 ){ print( counter ); counter = counter - 1; } else { print( "Blast off!" ); } prepare for countdown 10 print( "prepare for countdown " ); var counter = 10; settimeout( countdown, 1000 );

105 Callbacks var countdown = function() { if( counter > 0 ){ print( counter ); counter = counter - 1; settimeout( countdown, 1000); } else { print( "Blast off!" ); } print( "prepare for countdown " ); var counter = 10; settimeout( countdown, 1000 );

106 Callbacks var countdown = function() { if( counter > 0 ){ print( counter ); counter = counter - 1; settimeout( countdown, 1000); } else { print( "Blast off!" ); } print( "prepare for countdown " ); var counter = 10; settimeout( countdown, 1000 ); global variables are dangerous but can also be convenient

107 Callbacks and animation var drawframe = function() { background(); ellipse(x, y, 20, 20); // draw a ball // update the ball position x += vx; y += vy; var FRAME_DELAY = 50; // initial position for the ball, in global frame so // available each time: var x = 0; var y = 400; // initial velocity for ball var vx = 4; var vy = -4; if( 'timeoutid' in window ) cleartimeout( timeoutid ); timeoutid = setinterval(drawframe, FRAME_DELAY); animation

108 Callbacks and animation var drawframe = function() { background(); ellipse(x, y, 20, 20); // draw a ball // update the ball position x += vx; y += vy; var FRAME_DELAY = 50; // initial position for the ball, in global frame so // available each time: var x = 0; var y = 400; // initial velocity for ball var vx = 4; var vy = -2; if( 'timeoutid' in window ) cleartimeout( timeoutid ); timeoutid = setinterval(drawframe, FRAME_DELAY); how do we make ball bounce?

109 Callbacks and animation var drawframe = function() { background(); ellipse(x, y, 20, 20); // draw a ball // update the ball position x += vx; y += vy; if( x >= 400 x <= 0 ) vx = -vx; if( y >= 400 y <= 0 ) vy = -vy; var FRAME_DELAY = 50; // initial position for the ball, in global frame so // available each time: var x = 100; var y = 100; // initial velocity for ball var vx = 4; var vy = -2; if( 'timeoutid' in window ) cleartimeout( timeoutid ); timeoutid = setinterval(drawframe, FRAME_DELAY);

THE JAVASCRIPT ARTIST 15/10/2016

THE JAVASCRIPT ARTIST 15/10/2016 THE JAVASCRIPT ARTIST 15/10/2016 Objectives Learn how to program with JavaScript in a fun way! Understand the basic blocks of what makes a program. Make you confident to explore more complex features of

More information

CS110: PROGRAMMING LANGUAGE I

CS110: PROGRAMMING LANGUAGE I CS110: PROGRAMMING LANGUAGE I Computer Science Department Lecture 8: Methods Lecture Contents: 2 Introduction Program modules in java Defining Methods Calling Methods Scope of local variables Passing Parameters

More information

Iteration in Programming

Iteration in Programming Iteration in Programming for loops Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list There are three types of loop in programming: While

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 3 Lecture 3-2: Return values, Math, and double reading: 3.2, 2.1-2.2 Copyright 2011 by Pearson Education 2 Method name Math.abs(value) Math.ceil(value) Math.floor(value)

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 3 Lecture 3-2: Return values, Math, and double reading: 3.2, 2.1-2.2 Method name Math.abs(value) Math.ceil(value) Math.floor(value) Java's Math class Description absolute

More information

Interaction Design A.A. 2017/2018

Interaction Design A.A. 2017/2018 Corso di Laurea Magistrale in Design, Comunicazione Visiva e Multimediale - Sapienza Università di Roma Interaction Design A.A. 2017/2018 7 Conditionals in Processing Francesco Leotta, Andrea Marrella

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 3 Lecture 3-2: Return values, Math, and double reading: 3.2, 2.1-2.2 Java's Math class Method name Math.abs(value) Math.ceil(value) Math.floor(value) Description absolute

More information

! Widely available. ! Widely used. ! Variety of automatic checks for mistakes in programs. ! Embraces full set of modern abstractions. Caveat.

! Widely available. ! Widely used. ! Variety of automatic checks for mistakes in programs. ! Embraces full set of modern abstractions. Caveat. Why Java? Lecture 2: Intro to Java Java features.! Widely available.! Widely used.! Variety of automatic checks for mistakes in programs.! Embraces full set of modern abstractions. Caveat.! No perfect

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 3 Return values, Math, and double reading: 3.2, 2.1-2.2 Copyright 2011 by Pearson Education 2 Java's Math class Method name Math.abs(value) Math.ceil(value) Math.floor(value)

More information

CISC 110 Week 3. Expressions, Statements, Programming Style, and Test Review

CISC 110 Week 3. Expressions, Statements, Programming Style, and Test Review CISC 110 Week 3 Expressions, Statements, Programming Style, and Test Review Today Review last week Expressions/Statements Programming Style Reading/writing IO Test review! Trace Statements Purpose is to

More information

Lecture 6: While Loops and the Math Class

Lecture 6: While Loops and the Math Class Lecture 6: While Loops and the Math Class Building Java Programs: A Back to Basic Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson 2013. All rights reserved. while loops 2 Categories of loops

More information

Chapter 5 Methods. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved.

Chapter 5 Methods. Liang, Introduction to Java Programming, Eighth Edition, (c) 2011 Pearson Education, Inc. All rights reserved. Chapter 5 Methods 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Problem int sum = 0; for (int i = 1; i

More information

A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University 2011 Pearson Prentice Hall ISBN

A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University 2011 Pearson Prentice Hall ISBN A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University 2011 Pearson Prentice Hall ISBN 978-0-13-216675-1 Chapter 7 Functions and Randomness 1 Predefined Functions recall: in

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 3 Lecture 7: Return values, Math, and casting reading: 3.2, 2.1-2.2 (Slides adapted from Stuart Reges, Hélène Martin, and Marty Stepp) Copyright 2011 by Pearson Education

More information

A Balanced Introduction to Computer Science, 3/E

A Balanced Introduction to Computer Science, 3/E A Balanced Introduction to Computer Science, 3/E David Reed, Creighton University 2011 Pearson Prentice Hall ISBN 978-0-13-216675-1 Chapter 7 Functions and Randomness 1 Predefined Functions recall: in

More information

Kimberly Nguyen Professor Oliehoek Assignment 3. 1 A // Declare frequented variables int h = 20; void setup() { size(400, 200); smooth(); }

Kimberly Nguyen Professor Oliehoek Assignment 3. 1 A // Declare frequented variables int h = 20; void setup() { size(400, 200); smooth(); } 1 A // Declare frequented variables int w = 20; int h = 20; size(400, 200); void drawflashlight(int coloring,int i) { // Draw 8 dim flashlights for (int x = 0; x < width; x+=width/(i)) { ellipsemode(corner);

More information

To define methods, invoke methods, and pass arguments to a method ( ). To develop reusable code that is modular, easy-toread, easy-to-debug,

To define methods, invoke methods, and pass arguments to a method ( ). To develop reusable code that is modular, easy-toread, easy-to-debug, 1 To define methods, invoke methods, and pass arguments to a method ( 5.2-5.5). To develop reusable code that is modular, easy-toread, easy-to-debug, and easy-to-maintain. ( 5.6). To use method overloading

More information

1.1 Your First Program

1.1 Your First Program 1.1 Your First Program Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 5/20/2013 9:37:22 AM Why Programming? Why programming? Need

More information

Coding in JavaScript functions

Coding in JavaScript functions Coding in JavaScript functions A function contains code that will be executed by an event or by a call to the function. You may call a function from anywhere within a page (or even from other pages if

More information

Khan Academy JavaScript Study Guide

Khan Academy JavaScript Study Guide Khan Academy JavaScript Study Guide Contents 1. Canvas graphics commands with processing.js 2. Coloring 3. Variables data types, assignments, increments 4. Animation with draw loop 5. Math expressions

More information

Lecture 2: Intro to Java

Lecture 2: Intro to Java Why Java? Lecture 2: Intro to Java Java features. Widely available. Widely used. Variety of automatic checks for mistakes in programs. Embraces full set of modern abstractions. 2 Why Java? Why Java? Java

More information

12. Numbers. Java. Summer 2008 Instructor: Dr. Masoud Yaghini

12. Numbers. Java. Summer 2008 Instructor: Dr. Masoud Yaghini 12. Numbers Java Summer 2008 Instructor: Dr. Masoud Yaghini Outline Numeric Type Conversions Math Class References Numeric Type Conversions Numeric Data Types (Review) Numeric Type Conversions Consider

More information

Lecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science)

Lecture 14. Introduction to JavaScript. Mr. Mubashir Ali Lecturer (Dept. of Computer Science) Lecture 14 Introduction to JavaScript Mr. Mubashir Ali Lecturer (Dept. of dr.mubashirali1@gmail.com 1 Outline What is JavaScript? Embedding JavaScript with HTML JavaScript conventions Variables in JavaScript

More information

Interaction Design A.A. 2017/2018

Interaction Design A.A. 2017/2018 Corso di Laurea Magistrale in Design, Comunicazione Visiva e Multimediale - Sapienza Università di Roma Interaction Design A.A. 2017/2018 8 Loops and Arrays in Processing Francesco Leotta, Andrea Marrella

More information

Part I: Introduction to Functions

Part I: Introduction to Functions Computer Science & Engineering 120 Learning to Code Organizing Code I Functions Part I: Introduction to Functions Christopher M. Bourke cbourke@cse.unl.edu Topic Overview Functions Why Functions? Defining

More information

1.1 Your First Program

1.1 Your First Program Why Programming? Idealized computer. "Please simulate the motion of a system of N heavenly bodies, subject to Newton's laws of motion and gravity." 1.1 Your First Program Prepackaged software solutions.

More information

Chapter 1 Introduction to Computers and the Internet

Chapter 1 Introduction to Computers and the Internet CPET 499/ITC 250 Web Systems Dec. 6, 2012 Review of Courses Chapter 1 Introduction to Computers and the Internet The Internet in Industry & Research o E Commerce & Business o Mobile Computing and SmartPhone

More information

1.1 Your First Program

1.1 Your First Program Why Programming? 1.1 Your First Program Why programming? Need to tell computer what to do. Please simulate the motion of N heavenly bodies, subject to Newton s laws of motion and gravity. Prepackaged software

More information

Princess Nourah bint Abdulrahman University. Computer Sciences Department

Princess Nourah bint Abdulrahman University. Computer Sciences Department Princess Nourah bint Abdulrahman University 1 And use http://www.w3schools.com/ JavaScript Objectives Introduction to JavaScript Objects Data Variables Operators Types Functions Events 4 Why Study JavaScript?

More information

Introduction to Computer Science Unit 2. Notes

Introduction to Computer Science Unit 2. Notes Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and

More information

1.1 Your First Program

1.1 Your First Program 1.1 Your First Program Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2002 2010 1/29/11 6:37 AM! Why Programming? Why programming? Need to

More information

If the ball goes off either the right or left edge, turn the ball around. If x is greater than width or if x is less than zero, reverse speed.

If the ball goes off either the right or left edge, turn the ball around. If x is greater than width or if x is less than zero, reverse speed. Conditionals 75 Reversing the Polarity of a Number When we want to reverse the polarity of a number, we mean that we want a positive number to become negative and a negative number to become positive.

More information

Chapter 5 Methods. Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk

Chapter 5 Methods. Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk Chapter 5 Methods Lecture notes for computer programming 1 Faculty of Engineering and Information Technology Prepared by: Iyad Albayouk ١ Introducing Methods A method is a collection of statements that

More information

Building Java Programs

Building Java Programs Building Java Programs Chapter 3 Lecture 3-2: Return; doubles and casting reading: 3.2, 4.1 videos: Ch. 3 #2 Copyright 2009 by Pearson Education Finish Car example Lecture outline Returns Java Math library

More information

Chapter 5 Methods / Functions

Chapter 5 Methods / Functions Chapter 5 Methods / Functions 1 Motivations A method is a construct for grouping statements together to perform a function. Using a method, you can write the code once for performing the function in a

More information

AP Computer Science A. Return values

AP Computer Science A. Return values AP Computer Science A Return values Distance between points Write a method that given x and y coordinates for two points prints the distance between them Pseudocode? Java's Math class Method name Math.abs(value)

More information

HTML5 and CSS3 More JavaScript Page 1

HTML5 and CSS3 More JavaScript Page 1 HTML5 and CSS3 More JavaScript Page 1 1 HTML5 and CSS3 MORE JAVASCRIPT 3 4 6 7 9 The Math Object The Math object lets the programmer perform built-in mathematical tasks Includes several mathematical methods

More information

Using Methods. More on writing methods. Dr. Siobhán Drohan Mairead Meagher. Produced by: Department of Computing and Mathematics

Using Methods. More on writing methods. Dr. Siobhán Drohan Mairead Meagher. Produced by: Department of Computing and Mathematics Using Methods More on writing methods Produced by: Dr. Siobhán Drohan Mairead Meagher Department of Computing and Mathematics http://www.wit.ie/ Topics list Method example: Eyes Method example: X s Overloading

More information

JAVASCRIPT BASICS. JavaScript Math Functions. The Math functions helps you to perform mathematical tasks

JAVASCRIPT BASICS. JavaScript Math Functions. The Math functions helps you to perform mathematical tasks JavaScript Math Functions Functions The Math functions helps you to perform mathematical tasks in a very way and lot of inbuilt mathematical functions which makes the programmers life easier. Typical example

More information

c.def (pronounced SEE-def) Language Reference Manual

c.def (pronounced SEE-def) Language Reference Manual c.def (pronounced SEE-def) Macromedia Flash TM animation language Language Reference Manual Dennis Rakhamimov (dr524@columbia.edu), Group Leader Eric Poirier (edp29@columbia.edu) Charles Catanach (cnc26@columbia.edu)

More information

AP Computer Science. Return values, Math, and double. Copyright 2010 by Pearson Education

AP Computer Science. Return values, Math, and double. Copyright 2010 by Pearson Education AP Computer Science Return values, Math, and double Distance between points Write a method that given x and y coordinates for two points prints the distance between them If you can t do all of it, pseudocode?

More information

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent

Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent Programming 2 Key Concept: all programs can be broken down to a combination of one of the six instructions Assignment Statements can create variables to represent information Input can receive information

More information

INTRODUCTION TO PROCESSING. Alark Joshi, Amit Jain, Jyh-haw Yeh and Tim Andersen

INTRODUCTION TO PROCESSING. Alark Joshi, Amit Jain, Jyh-haw Yeh and Tim Andersen INTRODUCTION TO PROCESSING Alark Joshi, Amit Jain, Jyh-haw Yeh and Tim Andersen What is Processing? Processing is a programming language designed to make programming easier Developers were frustrated with

More information

CS 112 Introduction to Programming

CS 112 Introduction to Programming CS 112 Introduction to Programming Animation (sleep and double buffering); Methods with Return; Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu

More information

CS 112 Introduction to Programming

CS 112 Introduction to Programming CS 112 Introduction to Programming Animation (sleep and double buffering); Methods with Return; Yang (Richard) Yang Computer Science Department Yale University 308A Watson, Phone: 432-6400 Email: yry@cs.yale.edu

More information

Chapter 6 Methods. Dr. Hikmat Jaber

Chapter 6 Methods. Dr. Hikmat Jaber Chapter 6 Methods Dr. Hikmat Jaber 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Problem int sum = 0; for (int i = 1; i

More information

1.1 Your First Program

1.1 Your First Program 1.1 Your First Program Introduction to Programming in Java: An Interdisciplinary Approach Robert Sedgewick and Kevin Wayne Copyright 2008 January 26, 2009 9:28 tt Why Programming? Idealized computer. "Please

More information

Chapter 5 Methods. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved.

Chapter 5 Methods. Liang, Introduction to Java Programming, Ninth Edition, (c) 2013 Pearson Education, Inc. All rights reserved. Chapter 5 Methods 1 Opening Problem Find the sum of integers from 1 to 10, from 20 to 30, and from 35 to 45, respectively. 2 Problem int sum = 0; for (int i = 1; i

More information

Calculations, Formatting and Conversions

Calculations, Formatting and Conversions Chapter 5 Calculations, Formatting and Conversions What is in This Chapter? In this chapter we discuss how to do basic math calculations as well as use some readily available Math functions in JAVA. We

More information

Introduction to Computer Science Unit 2. Notes

Introduction to Computer Science Unit 2. Notes Introduction to Computer Science Unit 2. Notes Name: Objectives: By the completion of this packet, students should be able to describe the difference between.java and.class files and the JVM. create and

More information

The JavaScript Language

The JavaScript Language The JavaScript Language INTRODUCTION, CORE JAVASCRIPT Laura Farinetti - DAUIN What and why JavaScript? JavaScript is a lightweight, interpreted programming language with object-oriented capabilities primarily

More information

Practice Written Examination, Fall 2016 Roger B. Dannenberg, instructor

Practice Written Examination, Fall 2016 Roger B. Dannenberg, instructor 15-104 Practice Written Examination, Fall 2016 Roger B. Dannenberg, instructor Possibly useful function signatures (italics mean an expression goes here ): createcanvas(w, h); width height key background(r,

More information

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand

COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Section 101 Computer Science 1 -- Prof. Michael A. Soderstrand COSC 236 Web Site You will always find the course material at: http://www.class-notes.us From this site you can click on the COSC-236

More information

CSc 110, Autumn Lecture 10: return values and math

CSc 110, Autumn Lecture 10: return values and math CSc 110, Autumn 2017 Lecture 10: return values and math Python's Math class Method name math.ceil(value) math.floor(value) math.log(value, base) math.sqrt(value) math.sinh(value) math.cosh(value) math.tanh(value)

More information

Lecture 2: Intro to Java

Lecture 2: Intro to Java Why Programming? Lecture 2: Intro to Java Idealized computer. "Please simulate the motion of a system of N heavenly bodies, subject to Newton's laws of motion and gravity." Prepackaged software solutions.

More information

CISC 1600 Lecture 3.1 Introduction to Processing

CISC 1600 Lecture 3.1 Introduction to Processing CISC 1600 Lecture 3.1 Introduction to Processing Topics: Example sketches Drawing functions in Processing Colors in Processing General Processing syntax Processing is for sketching Designed to allow artists

More information

Condi(onals and Loops

Condi(onals and Loops Condi(onals and Loops 1 Review Primi(ve Data Types & Variables int, long float, double boolean char String Mathema(cal operators: + - * / % Comparison: < > = == 2 A Founda(on for Programming any program

More information

mith College Computer Science CSC103 How Computers Work Week 6 Fall 2017 Dominique Thiébaut

mith College Computer Science CSC103 How Computers Work Week 6 Fall 2017 Dominique Thiébaut mith College Computer Science CSC103 How Computers Work Week 6 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu Ben Fry on Processing... http://www.youtube.com/watch?&v=z-g-cwdnudu An Example Mouse 2D

More information

Repetition is the reality and the seriousness of life. Soren Kierkegaard

Repetition is the reality and the seriousness of life. Soren Kierkegaard 6 Loops Loops 81 Repetition is the reality and the seriousness of life. Soren Kierkegaard What s the key to comedy? Repetition. What s the key to comedy? Repetition. Anonymous In this chapter: The concept

More information

What is a variable? a named location in the computer s memory. mousex mousey. width height. fontcolor. username

What is a variable? a named location in the computer s memory. mousex mousey. width height. fontcolor. username What is a variable? a named location in the computer s memory mousex mousey width height fontcolor username Variables store/remember values can be changed must be declared to store a particular kind of

More information

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created.

+ Inheritance. Sometimes we need to create new more specialized types that are similar to types we have already created. + Inheritance + Inheritance Classes that we design in Java can be used to model some concept in our program. For example: Pokemon a = new Pokemon(); Pokemon b = new Pokemon() Sometimes we need to create

More information

Functions, Randomness and Libraries

Functions, Randomness and Libraries Functions, Randomness and Libraries 1 Predefined Functions recall: in mathematics, a function is a mapping from inputs to a single output e.g., the absolute value function: -5 5, 17.3 17.3 in JavaScript,

More information

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls. Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:

More information

switch-case Statements

switch-case Statements switch-case Statements A switch-case structure takes actions depending on the target variable. 2 switch (target) { 3 case v1: 4 // statements 5 break; 6 case v2: 7. 8. 9 case vk: 10 // statements 11 break;

More information

حميد دانشور H_danesh_2000@yahoo.com 1 JavaScript Jscript VBScript Eg 2 JavaScript: the first Web scripting language, developed by Netscape in 1995 syntactic similarities

More information

Chapter 5. Condi.onals

Chapter 5. Condi.onals Chapter 5 Condi.onals Making Decisions If you wish to defrost, press the defrost bu=on; otherwise press the full power bu=on. Let the dough rise in a warm place un.l it has doubled in size. If the ball

More information

AP CS Unit 3: Control Structures Notes

AP CS Unit 3: Control Structures Notes AP CS Unit 3: Control Structures Notes The if and if-else Statements. These statements are called control statements because they control whether a particular block of code is executed or not. Some texts

More information

Algorithm Discovery and Design. Why are Algorithms Important? Representing Algorithms. Chapter 2 Topics: What language to use?

Algorithm Discovery and Design. Why are Algorithms Important? Representing Algorithms. Chapter 2 Topics: What language to use? Algorithm Discovery and Design Chapter 2 Topics: Representing Algorithms Algorithmic Problem Solving CMPUT101 Introduction to Computing (c) Yngvi Bjornsson & Jia You 1 Why are Algorithms Important? If

More information

Functions. Functions. nofill(); point(20, 30); float angle = map(i, 0, 10, -2, 2); parameters return values

Functions. Functions. nofill(); point(20, 30); float angle = map(i, 0, 10, -2, 2); parameters return values Functions parameters return values 06 Functions 1 Functions Code that is packaged so it can be run by name Often has parameters to change how the function works (but not always) Often performs some computation

More information

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char

Review. Primitive Data Types & Variables. String Mathematical operators: + - * / % Comparison: < > <= >= == int, long float, double boolean char Review Primitive Data Types & Variables int, long float, double boolean char String Mathematical operators: + - * / % Comparison: < > = == 1 1.3 Conditionals and Loops Introduction to Programming in

More information

CSE120 Wi18 Final Review

CSE120 Wi18 Final Review CSE120 Wi18 Final Review Practice Question Solutions 1. True or false? Looping is necessary for complex programs. Briefly explain. False. Many loops can be explicitly written out as individual statements

More information

1.1 Your First Program! Naive ideal. Natural language instructions.

1.1 Your First Program! Naive ideal. Natural language instructions. Why Programming? Why programming? Need to tell computer what you want it to do. 1.1 Your First Program Naive ideal. Natural language instructions. Please simulate the motion of these heavenly bodies, subject

More information

Evaluating Logical Expressions

Evaluating Logical Expressions Review Hue-Saturation-Brightness vs. Red-Green-Blue color Decimal, Hex, Binary numbers and colors Variables and Data Types Other "things," including Strings and Images Operators: Mathematical, Relational

More information

An Introduction to Processing

An Introduction to Processing An Introduction to Processing Creating static drawings Produced by: Mairead Meagher Dr. Siobhán Drohan Department of Computing and Mathematics http://www.wit.ie/ Topics list Coordinate System in Computing.

More information

CS177 Python Programming. Recitation 2 - Computing with Numbers

CS177 Python Programming. Recitation 2 - Computing with Numbers CS177 Python Programming Recitation 2 - Computing with Numbers Outline Data types. Variables Math library. Range Function What is data (in the context of programming)? Values that are stored and manipulated

More information

int a; int b = 3; for (a = 0; a < 8 b < 20; a++) {a = a + b; b = b + a;}

int a; int b = 3; for (a = 0; a < 8 b < 20; a++) {a = a + b; b = b + a;} 1. What does mystery(3) return? public int mystery (int n) { int m = 0; while (n > 1) {if (n % 2 == 0) n = n / 2; else n = 3 * n + 1; m = m + 1;} return m; } (a) 0 (b) 1 (c) 6 (d) (*) 7 (e) 8 2. What are

More information

Class #1. introduction, functions, variables, conditionals

Class #1. introduction, functions, variables, conditionals Class #1 introduction, functions, variables, conditionals what is processing hello world tour of the grounds functions,expressions, statements console/debugging drawing data types and variables decisions

More information

PROBLEM SOLVING AND PROGRAM. Looping statements Executing steps many times

PROBLEM SOLVING AND PROGRAM. Looping statements Executing steps many times PROBLEM SOLVING AND PROGRAM Looping statements Executing steps many times LOOPING What if there are a number of steps that must be done several times, would you re-write those steps for each time you needed

More information

The Math Class. Using various math class methods. Formatting the values.

The Math Class. Using various math class methods. Formatting the values. The Math Class Using various math class methods. Formatting the values. The Math class is used for mathematical operations; in our case some of its functions will be used. In order to use the Math class,

More information

Rationale for Map-Reduce

Rationale for Map-Reduce Rationale for Map-Reduce Map-reduce idea: An Example (part 1) This example uses JavaScript. // A trivial example: alert("i d like some Spaghetti!"); alert("i d like some Chocolate Moose!"); The above can

More information

CSc 110, Spring Lecture 11: return values and math

CSc 110, Spring Lecture 11: return values and math CSc 110, Spring 2018 Lecture 11: return values and math Python's Math class Method name math.ceil(value) math.floor(value) math.log(value, base) math.sqrt(value) math.sinh(value) math.cosh(value) math.tanh(value)

More information

Learning VB.Net. Tutorial 11 Functions

Learning VB.Net. Tutorial 11 Functions Learning VB.Net Tutorial 11 Functions Hello everyone welcome to vb.net tutorials. These are going to be very basic tutorials about using the language to create simple applications, hope you enjoy it. If

More information

MoreIntro.v. MoreIntro.v. Printed by Zach Tatlock. Oct 07, 16 18:11 Page 1/10. Oct 07, 16 18:11 Page 2/10. Monday October 10, 2016 lec02/moreintro.

MoreIntro.v. MoreIntro.v. Printed by Zach Tatlock. Oct 07, 16 18:11 Page 1/10. Oct 07, 16 18:11 Page 2/10. Monday October 10, 2016 lec02/moreintro. Oct 07, 16 18:11 Page 1/10 * Lecture 02 Set Implicit Arguments. Inductive list (A: Type) : Type := nil : list A cons : A > list A > list A. Fixpoint length (A: Type) (l: list A) : nat := nil _ => O cons

More information

University of Cincinnati. P5.JS: Getting Started. p5.js

University of Cincinnati. P5.JS: Getting Started. p5.js p5.js P5.JS: Getting Started Matthew Wizinsky University of Cincinnati School of Design HTML + CSS + P5.js File Handling & Management Environment Canvas Coordinates Syntax Drawing Variables Mouse Position

More information

1.1 Your First Program

1.1 Your First Program Why Programming? 1.1 Your First Program Why programming? Need to tell computer what you want it to do. Naive ideal. Natural language instructions. Please simulate the motion of these heavenly bodies, subject

More information

Bits and Bytes. How do computers compute?

Bits and Bytes. How do computers compute? Bits and Bytes How do computers compute? Representing Data All data can be represented with: 1s and 0s on/of true/false Numbers? Five volunteers... Binary Numbers Positional Notation Binary numbers use

More information

1.1 Your First Program

1.1 Your First Program 1.1 Your First Program 1 Why Programming? Why programming? Need to tell computer what you want it to do. Naive ideal. Natural language instructions. Please simulate the motion of these heavenly bodies,

More information

mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut

mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut mith College Computer Science CSC103 How Computers Work Week 7 Fall 2017 Dominique Thiébaut dthiebaut@smith.edu Important Review Does the animation leave a trace? Are the moving objects move without a

More information

Lecture 9: Arrays. Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp. Copyright (c) Pearson All rights reserved.

Lecture 9: Arrays. Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp. Copyright (c) Pearson All rights reserved. Lecture 9: Arrays Building Java Programs: A Back to Basics Approach by Stuart Reges and Marty Stepp Copyright (c) Pearson 2013. All rights reserved. Can we solve this problem? Consider the following program

More information

5/31/2006. Last Time. Announcements. Today. Variable Scope. Variable Lifetime. Variable Scope - Cont. The File class. Assn 3 due this evening.

5/31/2006. Last Time. Announcements. Today. Variable Scope. Variable Lifetime. Variable Scope - Cont. The File class. Assn 3 due this evening. Last Time Announcements The File class. Back to methods Passing parameters by value and by reference. Review class attributes. An exercise to review File I/O, look at passing by reference and the use of

More information

Defining Functions 1 / 21

Defining Functions 1 / 21 Defining Functions 1 / 21 Outline 1 Using and Defining Functions 2 Implementing Mathematical Functions 3 Using Functions to Organize Code 4 Passing Arguments and Returning Values 5 Filter, Lambda, Map,

More information

CS177 Python Programming. Recita4on 2 - Compu4ng with Numbers

CS177 Python Programming. Recita4on 2 - Compu4ng with Numbers CS177 Python Programming Recita4on 2 - Compu4ng with Numbers Outline Data types. Variables Math library. Range Func4on What is data (in the context of programming)? Values that are stored and manipulated

More information

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls.

Jump Statements. The keyword break and continue are often used in repetition structures to provide additional controls. Jump Statements The keyword break and continue are often used in repetition structures to provide additional controls. break: the loop is terminated right after a break statement is executed. continue:

More information

Control Structures/Lespérance 1

Control Structures/Lespérance 1 EEC1022 MOBILE COMPUTING What is control; how does it flow? equence versus elec%on Flow (a) (b) 1 2 A1 B1 C1 PROF. Y. LEPÉRANCE n Dept. of Electrical Engineering & Computer cience 1 2 A 1 A 2 true false

More information

Chapter 5 Methods. Modifier returnvaluetype methodname(list of parameters) { // method body; }

Chapter 5 Methods. Modifier returnvaluetype methodname(list of parameters) { // method body; } Chapter 5 Methods 5.1 Introduction A method is a collection of statements that are grouped together to perform an operation. You will learn how to: o create your own mthods with or without return values,

More information

Computer Programming I - Unit 2 Lecture 1 of 13

Computer Programming I - Unit 2 Lecture 1 of 13 1 of 13 Precedence, Mixed Expressions, Math Methods, and Output Fmatting I. Precedence Rules - der of operations Introduction example: 4 + 2 X 3 =? A) Parenthesis, Division Multiplication (from left to

More information

All program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax.

All program statements you write should be syntactically correct. Partial credit is not guaranteed with incorrect use of syntax. With Solutions in Red CS110 Introduction to Computing Fall 2012 Section 2 Exam 1 This is an open notes exam. Computers are not permitted. Your work on this exam must be your own. Answer all questions in

More information

CMPT 100 : INTRODUCTION TO

CMPT 100 : INTRODUCTION TO CMPT 100 : INTRODUCTION TO COMPUTING TUTORIAL #5 : JAVASCRIPT 2 GUESSING GAME 1 By Wendy Sharpe BEFORE WE GET STARTED... If you have not been to the first tutorial introduction JavaScript then you must

More information

Searching in General

Searching in General Searching in General Searching 1. using linear search on arrays, lists or files 2. using binary search trees 3. using a hash table 4. using binary search in sorted arrays (interval halving method). Data

More information

CSE341: Programming Languages Lecture 9 Function-Closure Idioms. Dan Grossman Winter 2013

CSE341: Programming Languages Lecture 9 Function-Closure Idioms. Dan Grossman Winter 2013 CSE341: Programming Languages Lecture 9 Function-Closure Idioms Dan Grossman Winter 2013 More idioms We know the rule for lexical scope and function closures Now what is it good for A partial but wide-ranging

More information