User Tools

Site Tools


programming_fundamentals_with_processing:ch03-places-to-put-things

Differences

This shows you the differences between two versions of the page.

Link to this comparison view

Next revision
Previous revision
Next revisionBoth sides next revision
programming_fundamentals_with_processing:ch03-places-to-put-things [2017/07/26 17:49] – created mithatprogramming_fundamentals_with_processing:ch03-places-to-put-things [2017/07/26 17:53] – [Math versus programming] mithat
Line 16: Line 16:
 $a = b + 20$ $a = b + 20$
  
-If I asked you what the value of $a$ is, you would probably reply "fifty-three," and you'd be right. In the above, both $a$ and $b$ are variables--they are expected to hold numbers whose values can change. The fact that the values can change is a central feature of variables in both mathematics and programming.+If I asked you what the value of $a$ is, you would probably reply "fifty-three," and you'd be right. In the above, both $a$ and $b$ are variables---they are expected to hold numbers whose values can change. The fact that the values can change is a central feature of variables in both mathematics and programming.
  
 Let's now look at a Processing program that does what the mathematics example above does. Let's now look at a Processing program that does what the mathematics example above does.
  
-**program ''%%variables1.pde%%'':** +<file java variables1.pde>
- +
-<code java>+
 void setup () { void setup () {
   int a;   int a;
Line 30: Line 28:
   a = b + 20;   a = b + 20;
 } }
-</code>+</file> 
 The second part of the example probably makes sense to you. It's really just the mathematical expressions with semicolons tacked onto the ends. (Remember that the end of a statement in Processing must be marked with a semicolon.) But you might be confused about the lines that begin with ''%%int%%''. Those are there because in Processing, as well as many other languages, you must explicitly state that you intend to use a variables before you use it. In other words, Processing expects you to say, "Hey, I plan to use a variable named //<somename>//," before you use it. The statements The second part of the example probably makes sense to you. It's really just the mathematical expressions with semicolons tacked onto the ends. (Remember that the end of a statement in Processing must be marked with a semicolon.) But you might be confused about the lines that begin with ''%%int%%''. Those are there because in Processing, as well as many other languages, you must explicitly state that you intend to use a variables before you use it. In other words, Processing expects you to say, "Hey, I plan to use a variable named //<somename>//," before you use it. The statements
  
Line 37: Line 36:
 int b; int b;
 </code> </code>
-do exactly that--they are **variable declarations**. They tell the Processing compiler that you plan to use two variables, one named ''%%a%%'' and the other named ''%%b%%''.((Some programming languages automatically create new variables for you as soon as you use them. Processing isn't one of those.+do exactly that---they are **variable declarations**. They tell the Processing compiler that you plan to use two variables, one named ''%%a%%'' and the other named ''%%b%%''.((Some programming languages automatically create new variables for you as soon as you use them. Processing isn't one of those.
 )) ))
  
-Processing's rules for variable declarations say only that you must declare a variable before you use it. This means that you don't have to bundle all declarations together.((Some popular languages require that you declare all the variables you will use at the very start of the code block in which you will use them. Processing is more flexible on this issue. +Processing's rules for variable declarations say only that you must declare a variable before you use it. This means that you don't have to bundle all declarations together.((Some popular languages require that you declare all the variables you will use at the very start of the code block in which you will use them. Processing is more flexible on this issue.)) So, in the above example, you could have written:
-)) So, in the above example, you could have written:+
  
 <code java> <code java>
Line 50: Line 48:
 a = b + 20; a = b + 20;
 </code> </code>
 +
 as well. as well.
  
programming_fundamentals_with_processing/ch03-places-to-put-things.txt · Last modified: 2017/07/26 18:06 by mithat

Donate Powered by PHP Valid HTML5 Valid CSS Driven by DokuWiki