-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy path535.html
More file actions
162 lines (154 loc) · 6.69 KB
/
Copy path535.html
File metadata and controls
162 lines (154 loc) · 6.69 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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
<h1 id="print">PRINT</h1>
<blockquote>
<p>PRINT [#file] [USING [format];] [expr|str [,|; [expr|str] …]</p>
</blockquote>
<p>Display numbers, strings or values of expressions. The symbol
<code>?</code> can be used instead of keyword PRINT. You can use USG
instead of USING.</p>
<p>If a file handle <code>#file</code> is given, the output of print
will be redirected to the corresponding file. See OPEN for more
information on handling files.</p>
<p>To gain more control of where your next PRINT statement will be
placed on screen, see LOCATE and AT.</p>
<h3 id="example-1-basic-usage">Example 1: Basic usage</h3>
<pre><code>print 1 ' Output: 1
print 1+1 ' Output: 2
print cos(pi) ' Output: -1
print "Text" ' Output: Text</code></pre>
<h3 id="example-2-print-strings-and-numbers">Example 2: Print strings
and numbers</h3>
<pre><code>print "abc" + "def" ' Output: adcdef
print "abc" + " def" ' Output: abc def
print "abc" + 1 + "def" + cos(pi) ' Output: abc1def-1
print "abc" + 1 + 2 + "def" ' Output: abc12def <- 1 and 2 are treated as strings</code></pre>
<h3 id="example-3-print-strings-and-variables">Example 3: Print strings
and variables</h3>
<pre><code>a = 1
b = 2
c = a + b
print "a = " + a ' Output a = 1
print "b = " + b ' Output b = 2
print "a + b = " + c ' Output c = 3</code></pre>
<h2 id="print-separators">PRINT SEPARATORS</h2>
<table>
<colgroup>
<col style="width: 21%" />
<col style="width: 78%" />
</colgroup>
<thead>
<tr class="header">
<th style="text-align: center;">Separator</th>
<th style="text-align: left;">Description</th>
</tr>
</thead>
<tbody>
<tr class="odd">
<td style="text-align: center;">TAB(n)</td>
<td style="text-align: left;">Moves cursor position to the nth
column.</td>
</tr>
<tr class="even">
<td style="text-align: center;">SPC(n)</td>
<td style="text-align: left;">Prints a number of spaces specified by
n.</td>
</tr>
<tr class="odd">
<td style="text-align: center;">;</td>
<td style="text-align: left;">Separates numbers, expressions or
strings</td>
</tr>
<tr class="even">
<td style="text-align: center;">,</td>
<td style="text-align: left;">Separates numbers, expressions or strings
and insert one TAB</td>
</tr>
</tbody>
</table>
<p>If <code>;</code> and <code>,</code> are used as last character of a
print command, carriage return/line feed (new line) will be suppressed
after printing.</p>
<p>In contrast to the <code>+</code> operator to concatenate the output
as shown in the examples above, the <code>,</code> and <code>;</code>
operators can be used to concatenate the output and at the same time
evaluate expressions.</p>
<h3 id="example-1-using-and">Example 1: Using , and ;</h3>
<pre><code>a = 1
b = 2
print "a + b = " + a + b ' Output: a + b = 12 <- a and b treated as strings
print "a + b = " ; a + b ' Output: a + b = 3 <- a + b was evaluated
print "a + b = " , a + b ' Output: a + b = 3 <- a + b was evaluated</code></pre>
<h3 id="example-2-suppress-new-line">Example 2: Suppress new line</h3>
<pre><code>print "abc"; ' <- new line suppressed
print "def"
' Output: abcdef</code></pre>
<h3 id="example-3-using-tab-and-spc">Example 3: Using TAB and SPC</h3>
<pre><code>print "1" + tab(5) + "2" ' Output 1 2
print "1" + spc(1) + "2" ' Output 1 2</code></pre>
<h2 id="print-using">PRINT USING</h2>
<p>PRINT USING uses the FORMAT function to display numbers and strings.
Unlike FORMAT it can also include literals.</p>
<p>When a PRINT USING command is executed the format will remain in
memory until a new format is passed. Calling <code>PRINT USING</code>
without a format string specifies that PRINT will use the format of the
previous call.</p>
<p>Using <code>_</code> (underscore) will print the next character as a
literal. The combination <code>_#</code>, for example, allows you to
include a number sign as a literal in your numeric format.</p>
<p>See FORMAT for more information on how to define the format
string.</p>
<h3 id="example-1-basic-usage-1">Example 1: Basic usage</h3>
<pre><code>a = 1000
b = 2000
PRINT USING "#,###.##"; a
PRINT USING "#,###.## "; a; b ' <- Format is applied to all variables
PRINT USING "a = #####.00 b = #####"; a; b ' <- One formated string with placeholders for two variables
' Output: 1,000.
' Output: 1,000. 2,000.
' Output: a = 1000.00 b = 2000 </code></pre>
<h3 id="example-2-apply-format-multiple-times">Example 2: Apply format
multiple times</h3>
<pre><code>a = 1000
b = 2000
PRINT USING "#,###.##" ' Store format string
PRINT a ' Print without format
PRINT USING; a ' Print with stored string
PRINT USING; b ' Print with stored string
PRINT USING "####.00"; a ' Print with new format string and store string
PRINT USING; b ' Print with stored string
' Output:
' 1000
' 1,000.
' 2,000.
' 1000.00
' 2000.00</code></pre>
<h2 id="print-using-vt100-codes">Print using VT100 codes</h2>
<p>Escape codes can be used with PRINT. For more information please read
the article “Escape codes”</p>
<h2 id="more-examples">More Examples</h2>
<h3 id="example-1-3-ways-to-print-hello">Example 1: 3 ways to print
hello</h3>
<pre><code>' 3 ways to print hello five time.bas 2016-03-05 SmallBASIC 0.12.2 [B+=MGA]
'It's all in the punctuation at the end of a print statement
'1) no punctiation = whole print lines CR=carriage return and
' LF=line feed, ready to go on next line
for i = 1 to 5
print "hello"
next
print : print '2 blank lines
'2) a comma which tabs to next avaiable tab column and will stay
' on same line until run out of coloumns
for i = 1 to 5
print "hello",
next
'the first print will finish the print line, the 2 two are blank lines
print "& this will finish the hello, line."
print : print
'3) a semicolon (and space after hello)
for i = 1 to 5
print "hello";" "; 'or just print "hello ";
next
print "... this line needs to be finsihed."</code></pre>
<h3 id="example-2-print-to-a-file">Example 2: Print to a file</h3>
<pre><code>Open "PRINT.TXT" For Output As #1
Print #1, "hello"
Close #1</code></pre>