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
|
<!DOCTYPE html>
<html lang="en" dir="ltr" class="no-js">
<head>
<meta charset="utf-8" />
<title>en:subroutine [BASIC 256 - Language Documentation]</title>
<link rel="stylesheet" type="text/css" href="lib/exe/cssc171c1dfe8519125bb40a349172b001a.css"/>
</head>
<body>
<div id="dokuwiki__site"><div id="dokuwiki__top" class="site dokuwiki mode_show tpl_dokuwiki ">
<div id="dokuwiki__header"><div class="pad group">
<div class="headings group">
<h1><a href="start.html" accesskey="h" title="[H]"><img src="lib/tpl/dokuwiki/images/logo.png" width="64" height="64" alt="" /> <span>BASIC 256 - Language Documentation</span></a></h1>
</div>
</div>
<div class="breadcrumbs">
<div class="youarehere"><span class="bchead">You are here: </span><span class="home"><bdi><a href="start.html" class="wikilink1" title="start">start</a></bdi></span> » <bdi><a href="en_start.html" class="wikilink1" title="en:start">en</a></bdi> » <bdi><span class="curid"><a href="en_subroutine.html" class="wikilink1" title="en:subroutine">subroutine</a></span></bdi></div>
</div>
<hr class="a11y" />
</div></div>
<div class="wrapper group">
<div id="dokuwiki__content"><div class="pad group">
<div class="pageId"><span>en:subroutine</span></div>
<div class="page group">
<div id="dw__toc">
<h3 class="toggle">Table of Contents</h3>
<div>
<ul class="toc">
<li class="level2"><div class="li"><a href="en_subroutine.html#subroutine_statement">Subroutine (Statement)</a></div>
<ul class="toc">
<li class="level3"><div class="li"><a href="en_subroutine.html#format">Format</a></div></li>
<li class="level3"><div class="li"><a href="en_subroutine.html#description">Description</a></div></li>
<li class="level3"><div class="li"><a href="en_subroutine.html#example">Example</a></div></li>
<li class="level3"><div class="li"><a href="en_subroutine.html#see_also">See Also</a></div></li>
<li class="level3"><div class="li"><a href="en_subroutine.html#history">History</a></div></li>
</ul></li>
</ul>
</div>
</div>
<h2 class="sectionedit1" id="subroutine_statement">Subroutine (Statement)</h2>
<div class="level2">
</div>
<h3 class="sectionedit2" id="format">Format</h3>
<div class="level3">
<p>
<strong>subroutine</strong> subroutine_name ( <em><a class="explain" href="en_expressions.html">variable_list</a></em> )<br/>
<em><a class="explain" href="en_programsyntax.html">statement(s)</a></em><br/>
<strong>end subroutine</strong>
</p>
<p>
<strong>subroutine</strong> subroutine_name$ ( <em><a class="explain" href="en_expressions.html">variable_list</a></em> )<br/>
<em><a class="explain" href="en_programsyntax.html">statement(s)</a></em><br/>
<strong>end subroutine</strong>
</p>
</div>
<h3 class="sectionedit3" id="description">Description</h3>
<div class="level3">
<p>
Create a subroutine (or subprogram) that will receive zero or more values and process those values. A subroutine does not return a value back to the user, it just does what you want it to do. Execution of a subroutine will terminate and control will be returned to the ”<a href="en_call.html" class="wikilink1" title="en:call">call</a>ing” program when a <a href="en_return.html" class="wikilink1" title="en:return">Return</a> statement is executed or by allowing the <em>End Subroutine</em> statement to be reached. All variables used within the subroutine, that have not been previously declared as <a href="en_global.html" class="wikilink1" title="en:global">Global</a>, will be local to the subroutine and will not change the values in the calling code.
</p>
<p>
Subroutine variables may a list of zero or more, comma separated, numeric or string variables. Arrays and variables may be passed by reference using the <a href="en_ref.html" class="wikilink1" title="en:ref">Ref</a> definition.
</p>
<p>
Subroutines should be defined at the bottom of your program, and can not be defined within another <a href="en_function.html" class="wikilink1" title="en:function">Function</a>, <span class="curid"><a href="en_subroutine.html" class="wikilink1" title="en:subroutine">Subroutine</a></span> or control block (<a href="en_ifthen.html" class="wikilink1" title="en:ifthen">If/Then</a>, <a href="http://doc.basic256.org/doku.php?id=en:dountil" class="wikilink1" title="en:dountil">Do/Until</a>, …)
</p>
</div>
<h3 class="sectionedit4" id="example">Example</h3>
<div class="level3">
<pre class="code"># 100 random circles
clg
for x = 1 to 100
call draw()
next x
end
function rnd(n)
rnd = int(rand*n)
end function
subroutine draw()
color rnd(256),rnd(256),rnd(256)
circle rnd(graphwidth), rnd(graphheight), rnd(graphwidth/10)
end subroutine</pre>
<p>
draws<br/>
<a href="http://doc.basic256.org/lib/exe/detail.php?id=en_subroutine&media=en:subroutine_circle.png" class="media" title="en:subroutine_circle.png"><img src="lib/exe/en_subroutine_circle.png" class="media" title="Circles" alt="Circles" /></a>
</p>
</div>
<h3 class="sectionedit5" id="see_also">See Also</h3>
<div class="level3">
</div>
<div class="plugin_include_content plugin_include__en:start">
<div class="level3">
<p>
<a href="en_case.html" class="wikilink1" title="en:case">Begin Case / Case / End Case</a>, <a href="en_call.html" class="wikilink1" title="en:call">Call</a>, <a href="en_continuedo.html" class="wikilink1" title="en:continuedo">Continue Do</a>, <a href="en_continuefor.html" class="wikilink1" title="en:continuefor">Continue For</a>, <a href="en_continuewhile.html" class="wikilink1" title="en:continuewhile">Continue While</a>, <a href="en_do.html" class="wikilink1" title="en:do">Do / Until</a>, <a href="en_end.html" class="wikilink1" title="en:end">End</a>, <a href="en_exitdo.html" class="wikilink1" title="en:exitdo">Exit Do</a>, <a href="en_exitfor.html" class="wikilink1" title="en:exitfor">Exit For</a>, <a href="en_exitwhile.html" class="wikilink1" title="en:exitwhile">Exit While</a>, <a href="en_for.html" class="wikilink1" title="en:for">For / Next</a>, <a href="en_function.html" class="wikilink1" title="en:function">Function</a>, <a href="en_global.html" class="wikilink1" title="en:global">Global</a>, <a href="en_goto.html" class="wikilink1" title="en:goto">Goto</a>, <a href="en_gosub.html" class="wikilink1" title="en:gosub">Gosub</a>, <a href="en_ifthen.html" class="wikilink1" title="en:ifthen">If Then</a>, <a href="en_pause.html" class="wikilink1" title="en:pause">Pause</a>, <a href="en_ref.html" class="wikilink1" title="en:ref">Ref</a>, <a href="en_rem.html" class="wikilink1" title="en:rem">Rem</a>, <a href="en_return.html" class="wikilink1" title="en:return">Return</a>, <span class="curid"><a href="en_subroutine.html" class="wikilink1" title="en:subroutine">Subroutine</a></span>, <a href="en_while.html" class="wikilink1" title="en:while">While / End While</a>
</p>
</div>
</div>
<div class="level3">
</div>
<h3 class="sectionedit9" id="history">History</h3>
<div class="level3">
<div class="table sectionedit10"><table class="inline">
<tr class="row0">
<td class="col0">0.9.9.1</td><td class="col1">New To Version</td>
</tr>
</table></div>
</div>
</div>
<div class="docInfo"><bdi>en/subroutine.txt</bdi> · Last modified: 2014/02/09 14:56 by <bdi>admin</bdi></div>
</div></div>
<hr class="a11y" />
</div>
<div id="dokuwiki__footer"><div class="pad">
<div class="license">Except where otherwise noted, content on this wiki is licensed under the following license: <bdi><a href="http://creativecommons.org/licenses/by-sa/3.0/" rel="license" class="urlextern">CC Attribution-Share Alike 3.0 Unported</a></bdi></div>
</div></div>
</div></div>
<div id="screen__mode" class="no"></div>
</body>
</html>
|