-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsimple04.html
More file actions
93 lines (84 loc) · 3.32 KB
/
Copy pathsimple04.html
File metadata and controls
93 lines (84 loc) · 3.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
---
layout: base.html
title: Simple HTML - Introducing variables
---
<section class="side-by-side">
<canvas class="game right" id="canvas" oncontextmenu="event.preventDefault()"></canvas>
<div>
<article>
<h1>Introducing variables</h1>
<p>When you write programs you often need to give the computer
information to work on. The computer stores this
information in spaces called variables
in its memory.</p>
<center><img src="{{ base_uri }}/img/usborne/simple-basic/img/05boxes.jpg"></center>
<p>The spaces in the computer's memory are rather like the empty boxes in this picture.
When you give the computer a piece of information you have to give it a label too.
The computer puts information in a space and labels it.
A labelled space is called a variable.</p>
<p>Type in the following line:</p>
<pre>
N=999
</pre>
<p>The letter <code>N</code> is the label for the variable, and <code>999</code> is the value to
be stored in a variable labelled <code>N</code>.</p>
<p>You might sometimes see this written <code>LET N=999</code>. You can leave out the <code>LET</code> on this computer.</p>
<aside>
<p>Note that here we're not writing a program, because there are no line numbers. This means that the computer immediately
runs the instruction we've typed.
</p>
</aside>
<p>Now let’s <code class="command">PRINT</code> out the value in the variable <code>N</code>:</p>
<pre>
PRINT N
</pre>
<p>You will see the number <code>999</code> printed out.</p>
<p>Try changing the value stored in <code>N</code> by typing the first line again, but
this time with a different number, and then <code class="command">PRINT</code> it out again.</p>
<h2>Strings</h2>
<p>In BASIC, words, letters and symbols are called <em>strings</em>. When you store a string in a variable,
you must type the string in quotes. A variable
that contains a string is called a <em>string variable</em>.
Its label always has a dollar sign at the end.</p>
<pre>
U$="UGLY MONSTER"
R$="RUBBISH"
S$="/&SILLY SYMBOLS!!"
</pre>
<p>String variable labels always end with a <code>$</code>. Variables that <em>don’t</em>
end with a <code>$</code>, like <code>N</code> above, are <em>numeric</em> variables. They
store numbers such as <code>42</code> or even <code>3.14</code>.</p>
<h2>Using <code class="command">PRINT</code> with variables</h2>
<p>To make the computer display the information stored in a
variable, you use <code class="command">PRINT</code> followed by the variable name.
Try running the program below to see how this works.</p>
<pre>
NEW
10 CLS
20 N=99
30 B$="BANANAS"
40 PRINT N
50 PRINT B$
RUN
</pre>
<h2>Naming variables</h2>
<p>It's a good idea to give a variable a name that will
help you remember what it contains.</p>
<center><img src="{{ base_uri }}/img/usborne/simple-basic/img/05naming.jpg"></center>
<p>Letters of the alphabet and words are usually used as names for variables.
You can also use numbers, as long as the variable name <em>starts</em> with a letter.</p>
<p>So rather than the single letter variable names we used above, it is easier to understand if we use longer names like:</p>
<pre>
NEW
10 CLS
20 QUANTITY=99
30 FRUIT$="BANANAS"
40 PRINT QUANTITY; FRUIT$
RUN
</pre>
<footer>
<a href="{{ base_uri }}/simple05" class="button">Next</a>
</footer>
</article>
</div>
</section>