epubjs
Version:
Render ePub documents in the browser, across many devices
92 lines (79 loc) • 4.55 kB
HTML
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<meta charset="utf-8"/>
<title>Getting Started with Processing</title>
<script type="text/javascript">
if(!window.atlasplugins) window.atlasplugins = {}
atlasplugins.codeMirrorSettings = {
theme: "3024-day"
}
</script>
<link href="http://fonts.googleapis.com/css?family=Open+Sans:400,300,600,700" rel="stylesheet" type="text/css"> </link>
<script type="text/javascript" src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js"> </script>
<script type="text/javascript" src="http://cdn.mathjax.org/mathjax/latest/MathJax.js?config=TeX-AMS-MML_HTMLorMML"> </script>
<link rel="stylesheet" type="text/css" href="theme/html/html.css"/>
<link rel="stylesheet" type="text/css" href="https://cdnjs.cloudflare.com/ajax/libs/codemirror/4.4.0/codemirror.min.css"/>
<link rel="stylesheet" type="text/css" href="https://d2uogd9jz9k9zm.cloudfront.net/processingjs-0.0.3.css"/>
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/2.1.1/jquery.min.js" type="text/javascript"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/4.4.0/codemirror.min.js" type="text/javascript"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/codemirror/4.5.0/mode/clike/clike.min.js" type="text/javascript"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/underscore.js/1.6.0/underscore-min.js" type="text/javascript"> </script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/processing.js/1.4.8/processing.min.js" type="text/javascript"> </script>
<script src="https://d2uogd9jz9k9zm.cloudfront.net/processingjs-0.0.3.min.js" type="text/javascript"> </script>
<script type="text/javascript">
$(function() {
// Make all non runnable examples readonly codemirrors
$('pre:not(*[data-executable], .CodeMirror pre)').each(function(i, el) {
var textArea = $('<textarea>' + el.innerHTML + '</textarea>')
$(el).replaceWith(textArea);
var editor = CodeMirror.fromTextArea(textArea[0], {
mode: "text/x-java",
theme: "3024-day",
readOnly: true,
viewportMargin: 0
});
});
});
</script>
<style type="text/css">
/* This needs to come last to set auto height, and html.css is always included first */
.CodeMirror {
height: auto;
font-size: 14px;
padding: 15px;
border-radius: 5px;
}
.CodeMirror-scroll {
overflow-y: hidden;
overflow-x: auto;
height: auto;
}
</style>
<script type="text/javascript" src="theme/html/epub.js"> </script>
<script type="text/javascript" src="theme/html/reader.js"> </script>
</head>
<body data-type="book" id="viewer">
<section data-type="appendix" data-pdf-bookmark="Appendix D. Variable Scope" id="variable_scope">
<h1>Variable Scope</h1>
<p>The rule of variable scope is defined simply: a variable created inside a block (code enclosed within braces: <code>{</code> and <code>}</code>) exists only inside that block. This means that a variable created inside <em>setup()</em> can be used only within the <em>setup()</em> block, and likewise, a variable declared inside <em>draw()</em> can be used only inside the <em>draw()</em> block. The exception to this rule is a variable declared outside of <em>setup()</em> and <em>draw()</em>. These variables can be used in both <em>setup()</em> and <em>draw()</em> (or inside any other function that you create). Think of the area outside of <em>setup()</em> and <em>draw()</em> as an implied code block. We call these variables <em>global variables</em>, because they can be used anywhere within the program. We call a variable that is used only within a single block a <em>local variable</em>. Following are a couple of code examples that further explain the concept. First:</p>
<pre data-type="programlisting">int i = 12; // Declare global variable i and assign 12
void setup() {
size(480, 320);
int i = 24; // Declare local variable i and assign 24
println(i); // Prints 24 to the console
}
void draw() {
println(i); // Prints 12 to the console
}</pre>
<p>And second:</p>
<pre data-type="programlisting">void setup() {
size(480, 320);
int i = 24; // Declare local variable i and assign 24
}
void draw() {
println(i); // ERROR! The variable i is local to setup()
}</pre>
</section>
</body>
</html>