-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathstatement_do.html
134 lines (131 loc) · 8.57 KB
/
statement_do.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>"do" Statement - TMBASIC</title>
<!-- favicon start -->
<link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
<link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
<link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
<link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
<link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
<link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
<link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
<link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
<link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
<link rel="icon" type="image/png" sizes="192x192" href="/android-icon-192x192.png">
<link rel="icon" type="image/png" sizes="32x32" href="/favicon-32x32.png">
<link rel="icon" type="image/png" sizes="96x96" href="/favicon-96x96.png">
<link rel="icon" type="image/png" sizes="16x16" href="/favicon-16x16.png">
<link rel="manifest" href="/manifest.json">
<meta name="msapplication-TileColor" content="#ffffff">
<meta name="msapplication-TileImage" content="/ms-icon-144x144.png">
<meta name="theme-color" content="#ffffff">
<!-- favicon end -->
<meta name="apple-mobile-web-app-title" content="TMBASIC">
<meta name="application-name" content="TMBASIC">
<meta name="msapplication-TileColor" content="#da532c">
<style>
* { -webkit-text-size-adjust: none; text-size-adjust: none; }
a, a > span.tt { color: #326ec8; text-decoration: none; }
a:hover { text-decoration: underline; }
body { font-family: "Segoe UI", "Helvetica Neue", "Helvetica", Arial, sans-serif; font-size: 16px; color: #444444; margin: 1cm auto; margin-bottom: 5cm; padding-top: 1cm; max-width: 900px; line-height: 165%; overflow-y: scroll; }
col { width: auto !important; }
div.backlinks { font-size: 10pt; position: absolute; margin-top: -1cm; line-height: 100%; white-space: nowrap; }
div.bar { font-size: 9pt; margin-top: 20px; }
div.bar > span { background: #f8f8f8; padding: 5px 10px 5px 10px; font-weight: 500; }
div.code div { text-indent: -2cm; padding-left: 2cm; }
div.code { padding: 3mm; margin-bottom: 5mm; background: #f8f8f8; margin-top: 8px; white-space: pre; }
div.indent { margin-left: 1cm; }
div.paragraphBreak { height: 16px; }
div#root { margin-left: 1cm; margin-right: 1cm; }
div#compatibilityTable { line-height: 100%; }
div#compatibilityTable > table > tbody > tr > td { vertical-align: middle; padding: 2mm; padding-right: 4mm; }
h1 { font-size: 40px; color: #333333; }
h1 > span.tt { letter-spacing: -2px; word-break: break-word; }
h1#tmbasic { display: none; }
h1, h2, h3, h4, h5 { font-weight: 400; letter-spacing: -0.38px; line-height: 100%; }
h2 { font-size: 28px; color: #ba3925; margin-top: 50px; }
h3 { color: #ba3925; font-size: 20px; }
img.screenshot { margin-top: 2mm; height: 275px; width: 434px; float: right; margin-left: 1cm; margin-right: 1mm; background: #bbbbbb; image-rendering: -webkit-optimize-contrast; }
nav { background: #353535; position: absolute; top: 0; left: 0; width: 100%; padding-top: 2mm; padding-bottom: 2mm; line-height: normal; font-size: 18px; }
nav > div { max-width: 900px; margin: 0 auto; }
nav > div > div { margin-left: 1cm; margin-right: 1cm; }
nav > div > div > a { margin-left: 5mm; color: #afafaf; }
nav > div > div > a:hover { color: #FFFFFF; border-radius: 0.5mm; text-decoration: none; }
nav > div > div > a:first-child { margin-left: 0; padding-left: 0; color: #f7f7f7; }
pre, code, div.code, span.tt { font-family: Consolas, monospace; letter-spacing: -0.5px; color: #19177c; }
pre, div.code { line-height: 100%; overflow-x: auto; overflow-y: hidden; margin-top: 0; }
pre.diagram { display: inline-block; color: #333333; line-height: 100%; overflow-x: auto; overflow-y: hidden; width: 100%; }
pre.taste { background: #000080; color: white; padding: 5px 0px 5px 10px; line-height: 120%; }
pre.taste i { font-style: normal; color: #FFFF00; }
pre.taste b { font-weight: normal; color: #C0C0C0; }
pre.taste strong { font-weight: normal; color: #FF8AE2; }
pre.taste u { text-decoration: none; color: #00FFFF; }
span.comment, span.comment span.string { color: #26a135; }
span.indent { white-space: pre; }
span.operator { color: #666666; }
span.string { color: #ba2121; }
span.tt { line-height: 0; }
span#docLabelShort { display: none; }
strong, th { font-weight: 600; }
table { border-collapse: collapse; }
td, th { border: 1px solid #d5d5d5; padding: 1mm; padding-left: 3mm; padding-right: 4mm; vertical-align: top; }
th { text-align: left; }
ul { padding-left: 5mm; }
@media only screen and (max-width: 900px) and (min-width: 750px) {
h1 { font-size: 32px; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }
img.screenshot { height: 233.75px; width: 368.9px; /* 85% */ }
}
@media only screen and (max-width: 750px) {
h1 { font-size: 32px; }
h2 { font-size: 24px; }
h3 { font-size: 18px; }
div#root { margin-left: 5mm; margin-right: 5mm; }
nav > div > div { margin-left: 5mm; margin-right: 5mm; }
div.backlinks { left: 5mm; }
h1, h2 { margin-left: 0; }
img.screenshot { float: none; margin-left: 0; margin-top: 0; height: 206.25px; width: 325.5px; /* 75% */ }
span#docLabelShort { display: inline; }
span#docLabelLong { display: none; }
}
@media only screen and (max-width: 350px) {
img.screenshot { height: 103.125px; width: 162.75px; /* 37.5% */ }
nav { zoom: 0.80; }
div.indent { margin-left: 0; }
span#docLabelShort { display: inline; }
span#docLabelLong { display: none; }
nav > div > div > a:first-child { font-size: 25px; }
}
</style>
</head>
<body>
<nav>
<div><div><a href="/" style="font-weight: 600;">TMBASIC</a><a href="doc.html"><span id="docLabelLong">Documentation</span><span id="docLabelShort">Docs</span></a><a href="https://github.com/tmbasic/tmbasic">GitHub</a></div></div>
</nav>
<div id="root">
<div class="backlinks"><a href="doc.html">TMBASIC Documentation</a></div><h1><span class="tt">do</span> Statement</h1>A <span class="tt">do</span> loop is one way to repeat a section of code more than once.
After each time the loop is executed, the condition is checked.
If the condition is <span class="tt">true</span>, then the loop body starts over from the top.<div class="paragraphBreak"></div>Because the condition is checked after the loop body, a <span class="tt">do</span> loop will always execute at least once.<h2>Syntax</h2><div class="code"><div>do</div><div><span class="indent"> </span><BODY></div><div>loop while <CONDITION></div></div><ul><li><span class="tt"><BODY></span> is the code to execute repeatedly.</li><li><span class="tt"><CONDITION></span> is a Boolean expression indicating whether the loop should repeat for another iteration.</li></ul><h2>Usage</h2>Consider the following example.<div class="paragraphBreak"></div><div class="code"><div>sub Main()</div><div><span class="indent"> </span>dim num as Number</div><div><span class="indent"> </span>do</div><div><span class="indent"> </span><span class="indent"> </span>print <span class="string">"Enter a number: "</span>;</div><div><span class="indent"> </span><span class="indent"> </span>input num</div><div><span class="indent"> </span>loop while num <> 0</div><div>end sub</div></div>The execution looks like the following flow chart.<div class="paragraphBreak"></div><div><pre class="diagram"> ↓
┌───────────────────────────┐
┌─>│ print "Enter a number: "; │
│ └───────────────────────────┘
│ ↓
│ ┌───────────┐
│ │ input num │
│ └───────────┘
│ ↓
│ ┌──────┐
└───────────│ num? │
num <> 0 └──────┘
↓ num = 0
</pre></div>This is similar to a <a href="statement_while.html"><span class="tt">while</span> loop</a>.
In a <span class="tt">do</span> loop, the condition is checked <i>after</i> running the loop body.
In a <span class="tt">while</span> loop, the condition is checked <i>before</i> running the loop body.
This means that a <span class="tt">do</span> loop will always execute at least once, but a <span class="tt">while</span> loop can execute zero times.
</div>
</body>
</html>