lecture4.functions - Media Software Design DIG 3134 Lecture...

Info iconThis preview shows pages 1–18. Sign up to view the full content.

View Full Document Right Arrow Icon
1 DIG 3134 Lecture 4: Functions Michael Moshell University of Central Florida Media Software Design
Background image of page 1

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
2 The Objective: Learn what a function is, how to make one, and how to use it.
Background image of page 2
3 What is a function? Think of it as a machine. You put in some inputs, and it does some work, and produces some outputs. 4 square($n) 16 print "Four squared is".square(4); Four squared is 16
Background image of page 3

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
4 How do you make a function You define it like this: function square($n) { $product=$n*$n; return $product; }
Background image of page 4
5 How do you make a function You define it like this: function square($n) { $product=$n*$n; return $product; } // and then you "Call" it like this. $x=square(5); // or like this print square(6); function name
Background image of page 5

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
6 How do you make a function You define it like this: function square($n) { $product=$n*$n; return $product; } // and then you "Call" it like this. $x=square(5); // or like this print square(6); input ("argument, or "parameter")
Background image of page 6
7 How do you make a function You define it like this: function square($n) { $product=$n*$n; return $product; } // and then you "Call" it like this. $x=square(5); // or like this print square(6); output, or "return value"
Background image of page 7

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
8 How do you make a function You define it like this: function square($n) { $value=$n*$n; return $value; } // and then you "Call" it like this. $x=square(5); // or like this print square(6); using the function
Background image of page 8
9 How do you make a function You define it like this: function square($n) { $value=$n*$n; return $value; } // and then you "Call" it like this. $x=square(5); // or like this print square(6); $x is now 25 36
Background image of page 9

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
10 Here's a fancier function. function makebox($height,$width) { $answer='<table>'; for ($row=1; $row<=$height;$row++) { $answer .='<tr>'; for ($col=1; $col<=$width; $col++) { $answer.='<td>*</td>'; } $answer .='</tr>'; } $answer .='</table>'; return $answer; } print makebox(3,4); * * * * * * * * * * * *
Background image of page 10
11 function makebox($height,$width) { $answer='<table>'; for ($row=1; $row<=$height;$row++) { $answer .='<tr>'; for ($col=1; $col<=$width; $col++) { $answer.='<td>*</td>'; } $answer .='</tr>'; } $answer .='</table>'; return $answer; } print makebox(3,4); * * * * * * * * * * * * function name Here's a fancier function.
Background image of page 11

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
12 function makebox($height,$width) { $answer='<table>'; for ($row=1; $row<=$height;$row++) { $answer .='<tr>'; for ($col=1; $col<=$width; $col++) { $answer.='<td>*</td>'; } $answer .='</tr>'; } $answer .='</table>'; return $answer; } print makebox(3,4); * * * * * * * * * * * * arguments, or parameters Here's a fancier function.
Background image of page 12
13 function makebox($height,$width) { $answer='<table>'; for ($row=1; $row<=$height;$row++) { $answer .='<tr>'; for ($col=1; $col<=$width; $col++) { $answer.='<td>*</td>'; } $answer .='</tr>'; $answer .='</table>'; return $answer; } print makebox(3,4); * * * * * * * * * * * * output value Here's a fancier function.
Background image of page 13

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
14 function makebox($height,$width) { $answer='<table>'; for ($row=1; $row<=$height;$row++) { $answer .='<tr>'; for ($col=1; $col<=$width; $col++) { $answer.='<td>*</td>'; } $answer .='</tr>'; } $answer .='</table>'; return $answer; } print makebox(3,4); * * * * * * * * * * * * function declaration Here's a fancier function.
Background image of page 14
15 function makebox($height,$width) { $answer='<table>'; for ($row=1; $row<=$height;$row++) { $answer .='<tr>'; for ($col=1; $col<=$width; $col++) { $answer.='<td>*</td>'; } $answer .='</tr>'; } $answer .='</table>'; return $answer; } print makebox(3,4); * * * * * * * * * * * * function Invocation ("call") Here's a fancier function.
Background image of page 15

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
16 Returning a value function makebox($height,$width) { $answer='<table>'; for ($row=1; $row<=$height;$row++) { $answer .='<tr>'; for ($col=1; $col<=$width; $col++) { $answer.='<td>*</td>'; } $answer .='</tr>'; } $answer .='</table>'; return $answer; } print makebox(3,4); * * * * * * * * * * * * Return statement
Background image of page 16
17 NOT Returning a value Not all functions have to return a value.
Background image of page 17

Info iconThis preview has intentionally blurred sections. Sign up to view the full version.

View Full DocumentRight Arrow Icon
Image of page 18
This is the end of the preview. Sign up to access the rest of the document.

This note was uploaded on 08/25/2011 for the course DIG 3134 taught by Professor Moshell during the Fall '11 term at University of Central Florida.

Page1 / 45

lecture4.functions - Media Software Design DIG 3134 Lecture...

This preview shows document pages 1 - 18. Sign up to view the full document.

View Full Document Right Arrow Icon
Ask a homework question - tutors are online