<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /><title>Yabasic</title><meta name="generator" content="DocBook XSL Stylesheets V1.68.1" /></head><body><div class="book" lang="en" xml:lang="en"><div class="titlepage"><div><div><h1 class="title"><a id="id2407818"></a>Yabasic</h1></div></div><hr /></div><div class="toc"><p><b>Table of Contents</b></p><dl><dt><span class="chapter"><a href="#chapter_intoduction">1. Introduction</a></span></dt><dd><dl><dt><span class="sect1"><a href="#id2498654">About this document</a></span></dt><dt><span class="sect1"><a href="#id2455854">About <span class="application">yabasic</span></a></span></dt></dl></dd><dt><span class="chapter"><a href="#chapter_program_windows">2. The <span class="application">yabasic</span>-program under Windows</a></span></dt><dd><dl><dt><span class="sect1"><a href="#id2455307">Starting <span class="application">yabasic</span></a></span></dt><dt><span class="sect1"><a href="#id2455554">Options</a></span></dt><dt><span class="sect1"><a href="#id2452869">The context Menu</a></span></dt></dl></dd><dt><span class="chapter"><a href="#chapter_program_unix">3. The <span class="application">yabasic</span>-program under Unix</a></span></dt><dd><dl><dt><span class="sect1"><a href="#id2453000">Starting <span class="application">yabasic</span></a></span></dt><dt><span class="sect1"><a href="#id2510849">Options</a></span></dt><dt><span class="sect1"><a href="#id2511361">Setting defaults</a></span></dt></dl></dd><dt><span class="chapter"><a href="#chapter_topics">4. Some features of <span class="application">yabasic</span>, explained by topic</a></span></dt><dd><dl><dt><span class="sect1"><a href="#id2511460"><code class="function">print</code>, <code class="function">input</code> and others</a></span></dt><dt><span class="sect1"><a href="#id2511572">Control statements: loops, <code class="function">if</code> and <code class="function">switch</code></a></span></dt><dt><span class="sect1"><a href="#id2511842">Drawing and painting</a></span></dt><dt><span class="sect1"><a href="#id2512010">Reading from and writing to files</a></span></dt><dt><span class="sect1"><a href="#id2512101">Subroutines and Libraries</a></span></dt><dt><span class="sect1"><a href="#id2512181">String processing</a></span></dt><dt><span class="sect1"><a href="#id2512313">Arithmetic</a></span></dt><dt><span class="sect1"><a href="#id2512433">Data and such</a></span></dt><dt><span class="sect1"><a href="#id2512482">Other interesting commands.</a></span></dt></dl></dd><dt><span class="chapter"><a href="#chapter_topics_list">5. All commands and functions of <span class="application">yabasic</span> listed by topic</a></span></dt><dd><dl><dt><span class="sect1"><a href="#top_numbers">Number processing and conversion</a></span></dt><dt><span class="sect1"><a href="#top_conditions">Conditions and control structures</a></span></dt><dt><span class="sect1"><a href="#top_data">Data keeping and processing</a></span></dt><dt><span class="sect1"><a href="#top_strings">String processing</a></span></dt><dt><span class="sect1"><a href="#top_io">File operations and printing</a></span></dt><dt><span class="sect1"><a href="#top_sub">Subroutines and libraries</a></span></dt><dt><span class="sect1"><a href="#top_other">Other commands</a></span></dt><dt><span class="sect1"><a href="#top_graphics">Graphics and printing</a></span></dt></dl></dd><dt><span class="chapter"><a href="#chapter_ref_words">6. All commands and functions of <span class="application">yabasic</span> grouped alphabetically</a></span></dt><dd><dl><dt><span class="sect1"><a href="#ref_a">A</a></span></dt><dt><span class="sect1"><a href="#ref_b">B</a></span></dt><dt><span class="sect1"><a href="#ref_c">C</a></span></dt><dt><span class="sect1"><a href="#ref_d">D</a></span></dt><dt><span class="sect1"><a href="#ref_e">E</a></span></dt><dt><span class="sect1"><a href="#ref_f">F</a></span></dt><dt><span class="sect1"><a href="#ref_g">G</a></span></dt><dt><span class="sect1"><a href="#ref_h">H</a></span></dt><dt><span class="sect1"><a href="#ref_i">I</a></span></dt><dt><span class="sect1"><a href="#ref_l">L</a></span></dt><dt><span class="sect1"><a href="#ref_m">M</a></span></dt><dt><span class="sect1"><a href="#ref_n">N</a></span></dt><dt><span class="sect1"><a href="#ref_o">O</a></span></dt><dt><span class="sect1"><a href="#ref_p">P</a></span></dt><dt><span class="sect1"><a href="#ref_r">R</a></span></dt><dt><span class="sect1"><a href="#ref_s">S</a></span></dt><dt><span class="sect1"><a href="#ref_t">T</a></span></dt><dt><span class="sect1"><a href="#ref_u">U</a></span></dt><dt><span class="sect1"><a href="#ref_v">V</a></span></dt><dt><span class="sect1"><a href="#ref_w">W</a></span></dt><dt><span class="sect1"><a href="#ref_x">X</a></span></dt><dt><span class="sect1"><a href="#ref_special_characters">Special characters</a></span></dt><dt><span class="sect1"><a href="#reserved_word">Reserved Words</a></span></dt></dl></dd><dt><span class="chapter"><a href="#chapter_ref_concepts">7. A grab-bag of some general concepts and terms</a></span></dt><dd><dl><dt><span class="sect1"><a href="#ref_logical_shortcuts">Logical shortcuts</a></span></dt><dt><span class="sect1"><a href="#ref_conditions_and_expressions">Conditions and expressions</a></span></dt><dt><span class="sect1"><a href="#ref_array_references">References on arrays</a></span></dt><dt><span class="sect1"><a href="#ref_windows_filenames">Specifying Filenames under Windows</a></span></dt><dt><span class="sect1"><a href="#ref_escape_sequences">Escape-sequences</a></span></dt><dt><span class="sect1"><a href="#ref_standalone">Creating a <span class="emphasis"><em>standalone</em></span> program from your yabasic-program</a></span></dt></dl></dd><dt><span class="chapter"><a href="#chapter_examples">8. A few example programs</a></span></dt><dd><dl><dt><span class="sect1"><a href="#id2547195">A very simple program</a></span></dt><dt><span class="sect1"><a href="#id2547219">The demo of yabasic</a></span></dt></dl></dd><dt><span class="chapter"><a href="#chapter_copyright">9. The Copyright of <span class="application">yabasic</span></a></span></dt></dl></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="chapter_intoduction"></a>Chapter 1. Introduction</h2></div></div></div><div class="toc"><dl><dt><span class="sect1"><a href="#id2498654">About this document</a></span></dt><dt><span class="sect1"><a href="#id2455854">About <span class="application">yabasic</span></a></span></dt></dl></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2498654"></a>About this document</h2></div></div></div><p>
      This document describes <span class="application">yabasic</span>.
      You will find information about the <span class="application">yabasic</span> 
      interpreter (the program <span><strong class="command">yabasic</strong></span> under Unix or 
      <span><strong class="command">yabasic.exe</strong></span> under Windows)
      as well as the language (which is, of course, a sort of
<span class="acronym">basic</span>) itself.</p><p>
    </p><p>
      This document applies to version 2.760 of <span class="application">yabasic</span></p><p>
      However, this document does not contain the latest news about <span class="application">yabasic</span> or a FAQ.
      As such information tends to change rapidly, it is presented online only 
      at <a href="http://www.yabasic.de" target="_top">www.yabasic.de</a>.</p><p>
      Although <span class="acronym">basic</span> has its reputation as a language for beginning programmers,
      this is not an introduction to programming at large. Rather this text assumes, that
      the reader has some (moderate) experience with writing and starting computer programs.</p><p>
    </p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2455854"></a>About <span class="application">yabasic</span></h2></div></div></div><p><span class="application">yabasic</span> is a traditional basic interpreter. It understands most of the typical basic-constructs, like <code class="function">goto</code>, <code class="function">gosub</code>, line numbers, <code class="function">read</code>, <code class="function">data</code> or string-variables with a trailing '<code class="literal">$</code>'. But on the other hand, <span class="application">yabasic</span> implements some more advanced programming-constructs like subroutines or libraries (but <span class="emphasis"><em>not</em></span> objects). <span class="application">yabasic</span> works much the same under Unix and Windows.</p><p><span class="application">yabasic</span> puts emphasis on giving results quickly and easily; therefore simple commands are provided to open a graphic window, print the graphics or control the console screen and get keyboard or mouse information. The example below opens a window, draws a circle and prints the graphic:</p><pre class="programlisting">
open window 100,100
open printer
circle 50,50,40
text 10,50,"Press any key to get a printout"
clear screen
inkey$
close printer
close window
</pre><p>This example has fewer lines, than it would have in many other programming languages. In the end however <span class="application">yabasic</span> lacks behind more advanced and modern programming languages like C++ or Java. But as far as it goes it tends to give you results more quickly and easily.</p></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="chapter_program_windows"></a>Chapter 2. The <span class="application">yabasic</span>-program under Windows</h2></div></div></div><div class="toc"><dl><dt><span class="sect1"><a href="#id2455307">Starting <span class="application">yabasic</span></a></span></dt><dt><span class="sect1"><a href="#id2455554">Options</a></span></dt><dt><span class="sect1"><a href="#id2452869">The context Menu</a></span></dt></dl></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2455307"></a>Starting <span class="application">yabasic</span></h2></div></div></div><p>Once, <span class="application">yabasic</span> has been set up correctly, there are three ways to start it:</p><div class="orderedlist"><ol type="1"><li><p><span class="emphasis"><em>Rightclick on your desktop:</em></span> The desktop menu appears with a submenu named <span class="emphasis"><em>new</em></span>. From this submenu choose <span class="application">yabasic</span>. This will create a new icon on your desktop. If you rightclick on this icon, its <a href="#windows_context_menu">context menu</a> will appear; choose <span class="guilabel">Execute</span> to execute the program.</p></li><li><p>As a variant of the way described above, you may simply <span class="emphasis"><em>create a file with the ending <code class="filename">.yab</code></em></span> (e.g. with your favorite editor). Everything else then works as described above.</p></li><li><p><span class="emphasis"><em>From the start-menu:</em></span> Choose <span class="application">yabasic</span> from your start-menu. A console-window will open and you will be asked to type in your program. Once you are finished, you need to type <code class="literal">return</code> twice, and <span class="application">yabasic</span> will parse and execute your program.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This is <span class="emphasis"><em>not</em></span> the preferred way of starting <span class="application">yabasic</span> ! Simply because the program, that you have typed, <span class="emphasis"><em>can not be saved</em></span> and will be lost inevitably ! There is no such thing as a <code class="function">save</code>-command and therefore no way to conserve the program, that you have typed. This mode is only intended for quick hacks, and short programs.</p></div></li></ol></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2455554"></a>Options</h2></div></div></div><p>Under Windows <span class="application">yabasic</span> will mostly be invoked by double-clicking on an appropriate icon; this way you do not have a chance to specify any of the commandline options below. However, advanced users may add some of those options to the appropriate entries in the registry.</p><p>All the options below may be abbreviated, as long as the abbreviation does not become ambiguous. For example, you may write <code class="literal">-e</code> instead of <code class="literal">-execute</code>.</p><div class="variablelist"><dl><dt><span class="term"><code class="literal">-help</code> or <code class="literal">-?</code></span></dt><dd><p>Prints a short help message, which itself describes two further help-options.</p></dd><dt><span class="term"><code class="literal">-version</code></span></dt><dd><p>Prints the version of <span class="application">yabasic</span>.</p></dd><dt><span class="term"><code class="literal">-geometry +<em class="replaceable"><code>X-POSITION</code></em>+<em class="replaceable"><code>Y-POSITION</code></em></code></span></dt><dd><p>Sets the position of the graphic window, that is opened by <code class="function">open window</code> (the <span class="emphasis"><em>size</em></span> of this window, of course, is specified within the <code class="function">open window</code>-command). An example would be <code class="literal">-geometry +20+10</code>, which would place the graphic window 10 pixels below the upper border and 20 pixels right of the left border of the screen. This value cannot be changed, once <span class="application">yabasic</span> has been started.</p></dd><dt><span class="term"><code class="literal">-font <em class="replaceable"><code>NAME-OF-FONT</code></em></code></span></dt><dd><p>Name of the font, which will be used for graphic-text; can be any of <code class="literal">decorative, dontcare, modern, roman, script, swiss</code>. You may append a fontsize (measured in pixels) to any of those fontnames; for example <code class="literal">-font swiss30</code> chooses a swiss-type font with a size of 30 pixels.</p></dd><dt><span class="term"><code class="literal">-bind <em class="replaceable"><code>NAME-OF-STANDALONE-PROGRAM</code></em></code></span></dt><dd><p>Create a standalone program (whose name is specified by <em class="replaceable"><code>NAME-OF-STANDALONE-PROGRAM</code></em>) from the <span class="application">yabasic</span>-program, that is specified on the commandline. See the section about <a href="#ref_standalone" title="Creating a standalone program from your yabasic-program">creating a <span class="emphasis"><em>standalone</em></span>-program</a> for details.</p></dd><dt><span class="term"><code class="literal">-execute <em class="replaceable"><code>A-PROGRAM-AS-A-SINGLE-STRING</code></em></code></span></dt><dd><p>With this option you may specify some <span class="application">yabasic</span>-code to be executed rigth away.This is useful for very short programs, which you do not want to save within a file. If this option is given, <span class="application">yabasic</span> will not read any code from a file. Let's say, you have forgotten some of the square numbers between 1 and 10; in this case the command <code class="literal">yabasic -e 'for a=1 to 10:print a*a:next a'</code> will give you the answer immediately.</p></dd><dt><span class="term"><code class="literal">-infolevel <em class="replaceable"><code>INFOLEVEL</code></em></code></span></dt><dd><p>Change the <span class="emphasis"><em>infolevel</em></span> of yabasic, where <em class="replaceable"><code>INFOLEVEL</code></em> can be one of <code class="literal">debug</code>, <code class="literal">note</code>, <code class="literal">warning</code>, <code class="literal">error</code> and <code class="literal">fatal</code> (the default is <code class="literal">warning</code>). This option changes the amount of debugging-information <span class="application">yabasic</span> produces. However, normally only the author of <span class="application">yabasic</span> (<span class="emphasis"><em>me</em></span> !) would want to change this.</p></dd><dt><span class="term"><code class="literal">-doc <em class="replaceable"><code>NAME-OF-A-PROGRAM</code></em></code></span></dt><dd><p>Print the <span class="emphasis"><em>embedded documentation</em></span> of the named program. The embedded documentation of a program consists of all the comments within the program, which start with the special keyword <code class="function"><a href="#ref_doc" title="doc">doc</a></code>. This documentation can also be seen by choosing the corresponding entry from the context-menu of any <span class="application">yabasic</span>-program.</p></dd><dt><span class="term"><code class="literal">-librarypath <em class="replaceable"><code>DIRECTORY-WITH-LIBRARIES</code></em></code></span></dt><dd><p>Change the directory, wherein libraries will be searched and imported (with the <code class="function"><a href="#ref_import" title="import">import</a></code>-command). See also <code class="function"><a href="#ref_import" title="import">this entry</a></code> for more information about the way, libraries are searched.</p></dd></dl></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2452869"></a>The context Menu</h2></div></div></div><p>Like every other icon under Windows, the icon of every <span class="application">yabasic</span>-program has a <span class="emphasis"><em>context menu</em></span> offering the most frequent operations, that may be applied to a <span class="application">yabasic</span>-program.</p><div class="variablelist"><dl><dt><span class="term"><span class="guilabel">Execute</span></span></dt><dd><p>This will invoke <span class="application">yabasic</span> to execute your program. The same happens, if you <span class="emphasis"><em>doubleclick</em></span> on the icon.</p></dd><dt><span class="term"><span class="guilabel">Edit</span></span></dt><dd><p><span class="application">notepad</span> will be invoked, allowing you to edit your program.</p></dd><dt><span class="term"><span class="guilabel">View docu</span></span></dt><dd><p>This will present the embedded documentation of your program. Embedded documentation is created with the special comment <code class="function"><a href="#ref_doc" title="doc">doc</a></code>.</p></dd></dl></div></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="chapter_program_unix"></a>Chapter 3. The <span class="application">yabasic</span>-program under Unix</h2></div></div></div><div class="toc"><dl><dt><span class="sect1"><a href="#id2453000">Starting <span class="application">yabasic</span></a></span></dt><dt><span class="sect1"><a href="#id2510849">Options</a></span></dt><dt><span class="sect1"><a href="#id2511361">Setting defaults</a></span></dt></dl></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2453000"></a>Starting <span class="application">yabasic</span></h2></div></div></div><p>If your system administrator (vulgo <span class="emphasis"><em>root</em></span>) has installed <span class="application">yabasic</span> correctly, there are three ways to start it:</p><div class="orderedlist"><ol type="1"><li><p>You may use your favorite editor (<span class="application">emacs</span>, <span class="application">vi</span> ?) to put your program into a file (e.g. <code class="filename">foo</code>). Make sure that the very first line starts with the characters '<code class="literal">#!</code>'  followed by the full pathname of <span class="application">yabasic</span> (e.g. '<code class="literal">#!/usr/local/bin/yabasic</code>'). This <span class="emphasis"><em>she-bang</em></span>-line ensures, that your Unix will invoke <span class="application">yabasic</span> to execute your program (see also the entry for the <a href="#ref_hash" title="#">hash</a>-character). Moreover, you will need to change the permissions of your <span class="application">yabasic</span>-program <code class="filename">foo</code>, e.g. <code class="literal">chmod u+x foo</code>. After that you may invoke <span class="application">yabasic</span> to invoke your program by simply typing <code class="literal">foo</code> (without even mentioning <span class="application">yabasic</span>). However, if your <code class="envar">PATH</code>-variable does not contain a single dot ('<code class="literal">.</code>') you will have to type the full pathname of your program: e.g. <code class="filename">/home/ihm/foo</code> (or at least <code class="filename">./foo</code>).</p></li><li><p>Save your program into a file (e.g. <code class="filename">foo</code>) and type <code class="literal">yabasic foo</code>. This assumes, that the directory, where <span class="application">yabasic</span> resides, is contained within your <code class="envar">PATH</code>-variable.</p></li><li><p>Finally your may simply type <strong class="userinput"><code>yabasic</code></strong> (maybe it will be necessary to include its full pathname). This will make <span class="application">yabasic</span> come up and you will be asked to type in your program. Once you are finished, you need to type <code class="literal">return</code> twice, and <span class="application">yabasic</span> will parse and execute your program.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>This is <span class="emphasis"><em>not</em></span> the preferred way of starting <span class="application">yabasic</span> ! Simply because the program, that you have typed, <span class="emphasis"><em>can not be saved</em></span> and will be lost inevitably ! There is no such thing as a <code class="function">save</code>-command and therefore no way to conserve the program, that you have typed. This mode is only intended for quick hacks, and short programs, i.e. for using <span class="application">yabasic</span> as some sort of fancy desktop calculator.</p></div></li></ol></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2510849"></a>Options</h2></div></div></div><p><span class="application">yabasic</span> accepts a number of options on the commandline. All these options below may be abbreviated, as long as the abbreviation does not become ambigous. For example you may write <code class="literal">-e</code> instead of <code class="literal">-execute</code>.</p><div class="variablelist"><dl><dt><span class="term"><code class="literal">-help</code> or <code class="literal">-?</code></span></dt><dd><p>Prints a short help message, which itself describes two further help-options.</p></dd><dt><span class="term"><code class="literal">-version</code></span></dt><dd><p>Prints the version of <span class="application">yabasic</span>.</p></dd><dt><span class="term"><code class="literal">-fg <em class="replaceable"><code>FOREGROUND-COLOR</code></em></code> or <code class="literal">-foreground <em class="replaceable"><code>FOREGROUND-COLOR</code></em></code></span></dt><dd><p>Define the foreground color for the graphics-window (that will be opened with <code class="function"><a href="#ref_open_window" title="open window">open window</a></code>). The usual X11 colornames, like <span class="emphasis"><em>red</em></span>, <span class="emphasis"><em>green</em></span>, … are accepted. This value cannot be changed, once <span class="application">yabasic</span> has been started.</p></dd><dt><span class="term"><code class="literal">-bg <em class="replaceable"><code>BACKGROUND-COLOR</code></em></code> or <code class="literal">-background <em class="replaceable"><code>BACKGROUND-COLOR</code></em></code></span></dt><dd><p>Define the background color for the graphics-window. The usual X11 colornames are accepted. This value cannot be changed, once <span class="application">yabasic</span> has been started.</p></dd><dt><span class="term"><code class="literal">-geometry +<em class="replaceable"><code>X-POSITION</code></em>+<em class="replaceable"><code>Y-POSITION</code></em></code></span></dt><dd><p>Sets the position of the graphic window, that is opened by <code class="function">open window</code> (the <span class="emphasis"><em>size</em></span> of this window, of course, is specified with the <code class="function">open window</code>-command). An example would be <code class="literal">+20+10</code>, which would place the graphic window 10 pixels below the upper border and 20 pixels right of the left border of the screen. Note, that the size of the window may not be specified here (well it may, but it will be ignored anyway). This value cannot be changed, once <span class="application">yabasic</span> has been started.</p></dd><dt><span class="term"><code class="literal">-display <em class="replaceable"><code>BACKGROUND-COLOR</code></em></code></span></dt><dd><p>Specify the <span class="emphasis"><em>display</em></span>, where the graphics window of yabasic should appear. Normally, however this value will be already present within the environment variable <code class="envar">DISPLAY</code>.</p></dd><dt><span class="term"><code class="literal">-font <em class="replaceable"><code>NAME-OF-FONT</code></em></code></span></dt><dd><p>Name of the font, which will be used for text within the graphics window.</p></dd><dt><span class="term"><code class="literal">-execute <em class="replaceable"><code>A-PROGRAM-AS-A-SINGLE-STRING</code></em></code></span></dt><dd><p>With this option you may specify some <span class="application">yabasic</span>-code to be executed rigth away.This is useful for very short programs, which you do not want to save to a file. If this option is given, <span class="application">yabasic</span> will not read any code from a file. E.g. </p><pre class="programlisting">yabasic -e 'for a=1 to 10:print a*a:next a'</pre><p> prints the square numbers from 1 to 10.
</p></dd><dt><span class="term"><code class="literal">-bind <em class="replaceable"><code>NAME-OF-STANDALONE-PROGRAM</code></em></code></span></dt><dd><p>Create a standalone program (whose name is specified by <em class="replaceable"><code>NAME-OF-STANDALONE-PROGRAM</code></em>) from the <span class="application">yabasic</span>-program, that is specified on the commandline. See the section about <a href="#ref_standalone" title="Creating a standalone program from your yabasic-program">creating a <span class="emphasis"><em>standalone</em></span>-program</a> for details.</p></dd><dt><span class="term"><code class="literal">-infolevel <em class="replaceable"><code>INFOLEVEL</code></em></code></span></dt><dd><p>Change the <span class="emphasis"><em>infolevel</em></span> of yabasic where <em class="replaceable"><code>INFOLEVEL</code></em> can be one of <code class="literal">debug</code>, <code class="literal">note</code>, <code class="literal">warning</code>, <code class="literal">error</code> and <code class="literal">fatal</code> (the default is <code class="literal">warning</code>). This option changes the amount of debugging-information <span class="application">yabasic</span> produces. However, normally only the author of <span class="application">yabasic</span> (<span class="emphasis"><em>me</em></span> !) would want to change this.</p></dd><dt><span class="term"><code class="literal">-doc <em class="replaceable"><code>NAME-OF-A-PROGRAM</code></em></code></span></dt><dd><p>Print the <span class="emphasis"><em>embedded documentation</em></span> of the named program. The embedded documentation of a program consists of all the comments within the program, which start with the special keyword <code class="function"><a href="#ref_doc" title="doc">doc</a></code>.</p></dd><dt><span class="term"><code class="literal">-librarypath <em class="replaceable"><code>DIRECTORY-WITH-LIBRARIES</code></em></code></span></dt><dd><p>Change the directory from which libraries will be imported (with the <code class="function"><a href="#ref_import" title="import">import</a></code>-command). See also this entry for more information about the way, libraries will be searched.</p></dd></dl></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2511361"></a>Setting defaults</h2></div></div></div><p>If you want to set some options <span class="emphasis"><em>once for all</em></span>, you may put them into your X-Windows resource file. This is usually the file <code class="filename">.Xresources</code> or some such within your home directory (type <strong class="userinput"><code>man X</code></strong> for details).</p><p>Here is a sample section, which may appear within this file:</p><pre class="programlisting">
yabasic*foreground: blue
yabasic*background: gold
yabasic*geometry: +10+10
yabasic*font: 9x15
</pre><p>This will set the foreground color of the graphic-window to <span class="emphasis"><em>blue</em></span> and the background color to <span class="emphasis"><em>gold</em></span>. The window will appear at position <span class="emphasis"><em>10,10</em></span> and the text font will be <span class="emphasis"><em>9x15</em></span>.</p></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="chapter_topics"></a>Chapter 4. Some features of <span class="application">yabasic</span>, explained by topic</h2></div></div></div><div class="toc"><dl><dt><span class="sect1"><a href="#id2511460"><code class="function">print</code>, <code class="function">input</code> and others</a></span></dt><dt><span class="sect1"><a href="#id2511572">Control statements: loops, <code class="function">if</code> and <code class="function">switch</code></a></span></dt><dt><span class="sect1"><a href="#id2511842">Drawing and painting</a></span></dt><dt><span class="sect1"><a href="#id2512010">Reading from and writing to files</a></span></dt><dt><span class="sect1"><a href="#id2512101">Subroutines and Libraries</a></span></dt><dt><span class="sect1"><a href="#id2512181">String processing</a></span></dt><dt><span class="sect1"><a href="#id2512313">Arithmetic</a></span></dt><dt><span class="sect1"><a href="#id2512433">Data and such</a></span></dt><dt><span class="sect1"><a href="#id2512482">Other interesting commands.</a></span></dt></dl></div><p>This chapter has sections for some of the major features of <span class="application">yabasic</span> and names a few commands related with each area. So, depending on your interest, you find the most important commands of this area named; the other commands from this area may then be discovered through the links in the <span class="emphasis"><em>see also</em></span>-section.</p><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2511460"></a><code class="function">print</code>, <code class="function">input</code> and others</h2></div></div></div><p>The <code class="function"><a href="#ref_print" title="print">print</a></code>-command is used to put text on the text screen. Here, the term <em class="wordasword">text screen</em> stands for your terminal (under Unix) or the console window (under Windows).</p><p>At the bottom line, <code class="function">print</code> simply outputs its argument to the text window. However, once you have called <code class="function"><a href="#ref_clear_screen" title="clear screen">clear screen</a></code> you may use advanced features like printing colors or copying areas of text with <code class="function"><a href="#ref_getscreen" title="getscreen$()">getscreen$</a></code> or <code class="function"><a href="#ref_putscreen" title="putscreen">putscreen</a></code>.</p><p>You may ask the user for input with the <code class="function"><a href="#ref_input" title="input">input</a></code>-command; use <code class="function"><a href="#ref_inkey" title="inkey$">inkey$</a></code> to get each key as soon as it is pressed.</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2511572"></a>Control statements: loops, <code class="function">if</code> and <code class="function">switch</code></h2></div></div></div><p>Of course, <span class="application">yabasic</span> has the <code class="function"><a href="#ref_goto" title="goto">goto</a></code>- and <code class="function"><a href="#ref_gosub" title="gosub">gosub</a></code>-statements; you may go to a <code class="function"><a href="#ref_label" title="label">label</a></code> or a <span class="emphasis"><em>line number</em></span> (which is just a special kind of label). <code class="function"><a href="#ref_goto" title="goto">goto</a></code>, despite its bad reputation ([<span class="citation"><code class="function">goto</code> considered harmful</span>]), has still its good uses; however in many cases you are probably better off with loops like <code class="function"><a href="#ref_repeat" title="repeat">repeat</a></code>-<code class="function"><a href="#ref_until" title="until">until</a></code>, <code class="function"><a href="#ref_while" title="while">while</a></code>-<code class="function"><a href="#ref_wend" title="wend">wend</a></code> or <code class="function"><a href="#ref_do" title="do">do</a></code>-<code class="function"><a href="#ref_loop" title="loop">loop</a></code>; you may leave any of these loops with the <code class="function"><a href="#ref_break" title="break">break</a></code>-statement or start the next iteration immediately with <code class="function"><a href="#ref_continue" title="continue">continue</a></code>.</p><p>Decisions can be made with the <code class="function"><a href="#ref_if" title="if">if</a></code>-statement, which comes either in a <span class="emphasis"><em>short</em></span> and a <span class="emphasis"><em>long</em></span> form. The short form has no <code class="function"><a href="#ref_then" title="then">then</a></code>-keyword and extends up to the end of the line. The long form extends up to the final <code class="function"><a href="#ref_endif" title="endif">endif</a></code> and may use some of the keywords <code class="function"><a href="#ref_then" title="then">then</a></code> (which introduces the long form), <code class="function"><a href="#ref_else" title="else">else</a></code> or <code class="function"><a href="#ref_elsif" title="elsif">elsif</a></code>.</p><p>If you want to test the result of an expression against many different values, you should probably use the <code class="function"><a href="#ref_switch" title="switch">switch</a></code>-statement.</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2511842"></a>Drawing and painting</h2></div></div></div><p>You need to call <code class="function"><a href="#ref_open_window" title="open window">open window</a></code> before you may draw anything with either <code class="function"><a href="#ref_line" title="line">line</a></code>, <code class="function"><a href="#ref_circle" title="circle">circle</a></code>, <code class="function"><a href="#ref_rectangle" title="rectangle">rectangle</a></code> or <code class="function"><a href="#ref_triangle" title="triangle">triangle</a></code>; all of these statements may be decorated with <code class="function"><a href="#ref_clear" title="clear">clear</a></code> or <code class="function"><a href="#ref_fill" title="fill">fill</a></code>. If you want to change the colour for drawing, use <code class="function"><a href="#ref_colour" title="colour">colour</a></code>. Note however, that there can only be a single window open at any given moment in time.</p><p>Everything you have drawn can be send to your printer too, if you use the <code class="function"><a href="#ref_open_printer" title="open printer">open printer</a></code> command.</p><p>To allow for some (very) limited version of animated graphics, <span class="application">yabasic</span> offers the commands <code class="function"><a href="#ref_getbit" title="getbit$()">getbit$</a></code> and <code class="function"><a href="#ref_putbit" title="putbit">putbit</a></code>, which retrieve rectangular regions from the graphics-window into a string or vice versa.</p><p>If you want to sense mouse-clicks, you may use the <code class="function"><a href="#ref_inkey" title="inkey$">inkey$</a></code>-function.</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2512010"></a>Reading from and writing to files</h2></div></div></div><p>Before you may read or write a file, you need to <code class="function"><a href="#ref_open" title="open">open</a></code> it; once you are done, you should <code class="function"><a href="#ref_close" title="close">close</a></code> it. Each open file is designated by a simple number, which might be stored within a variable and must be supplied if you want to access the file. This is simply done by putting a hash ('<code class="literal">#</code>') followed by the number of the file after the keyword <code class="function"><a href="#ref_input" title="input">input</a></code> (for reading from) or <code class="function"><a href="#ref_print" title="print">print</a></code> (for writing to a file) respectively.</p><p>If you need more control, you may consider reading and writing one byte at a time, using the multi-purpose commands <code class="function"><a href="#ref_peek" title="peek">peek</a></code> and <code class="function"><a href="#ref_poke" title="poke">poke</a></code>.</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2512101"></a>Subroutines and Libraries</h2></div></div></div><p>The best way to break any <span class="application">yabasic</span>-program into smaller, more manageable chunks are <span class="emphasis"><em>subroutines</em></span> and <span class="emphasis"><em>libraries</em></span>. They are <span class="application">yabasic</span>'s most advanced means of structuring a program.</p><p>Subroutines are created with the command <code class="function"><a href="#ref_sub" title="sub">sub</a></code>. they accept parameters and may return a value. Subroutines can be called much like any builtin function of <span class="application">yabasic</span>; therefore they allow to <span class="emphasis"><em>extend</em></span> the language itself.</p><p>Once you have created a set of related subroutines and you feel that they could be useful in other programs too, you may collect them into a <span class="emphasis"><em>library</em></span>. Such a library is contained within a separate file and may be included in any of your programs, using the keyword <code class="function"><a href="#ref_import" title="import">import</a></code>.</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2512181"></a>String processing</h2></div></div></div><p><span class="application">yabasic</span> has the usual functions to extract parts from a string: <code class="function"><a href="#ref_left" title="left$()">left$</a></code>, <code class="function"><a href="#ref_mid" title="mid$()">mid$</a></code> and <code class="function"><a href="#ref_right" title="right$()">right$</a></code>. Note, that all of them can be assigned to, i.e. they may <span class="emphasis"><em>change</em></span> part of a string.</p><p>If you want to split a string into tokens you should use the functions <code class="function"><a href="#ref_token" title="token()">token</a></code> or <code class="function"><a href="#ref_split" title="split()">split</a></code>.</p><p>There is quite a bunch of other string-processing functions like <code class="function"><a href="#ref_upper" title="upper$()">upper$</a></code> (converting to upper case), <code class="function"><a href="#ref_instr" title="instr()">instr</a></code> (finding one string within the other), <code class="function"><a href="#ref_chr" title="chr$()">chr$</a></code> (converting an ascii-code into a character), <code class="function"><a href="#ref_glob" title="glob()">glob</a></code> (testing a string against a pattern) and more. Just follow the links.</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2512313"></a>Arithmetic</h2></div></div></div><p><span class="application">Yabasic</span> handles numbers and arithmetic: You may calculate trigonometric functions like <code class="function"><a href="#ref_sin" title="sin()">sin</a></code> or <code class="function"><a href="#ref_atan" title="atan()">atan</a></code>, or logarithms (with <code class="function"><a href="#ref_log" title="log()">log</a></code>). Bitwise operations, like <code class="function"><a href="#ref_arithmetic_and" title="and()">and</a></code> or <code class="function"><a href="#ref_arithmetic_or" title="or()">or</a></code> are available as well <code class="function"><a href="#ref_min" title="min()">min</a></code> or <code class="function"><a href="#ref_max" title="max()">max</a></code> (calculate the minimum or maximum of its argument) or <code class="function"><a href="#ref_mod" title="mod()">mod</a></code> or <code class="function"><a href="#ref_int" title="int()">int</a></code> (reminder of a division or integer part or a number).</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2512433"></a>Data and such</h2></div></div></div><p>You may store data within your program within <code class="function"><a href="#ref_data" title="data">data</a></code>-statements; during execution you will probably want to <code class="function"><a href="#ref_read" title="read">read</a></code> it into <span class="emphasis"><em>arrays</em></span>, which must have been <code class="function"><a href="#ref_dim" title="dim">dim</a></code>ed before.</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2512482"></a>Other interesting commands.</h2></div></div></div><div class="itemizedlist"><ul type="disc"><li><p><span class="application">Yabasic</span> programs may start other programs with the commands <code class="function"><a href="#ref_system" title="system$()">system</a></code> and <code class="function"><a href="#ref_system2" title="system()">system$</a></code>.</p></li><li><p><code class="function"><a href="#ref_peek" title="peek">peek</a></code> and <code class="function"><a href="#ref_poke" title="poke">poke</a></code> allow to get and set internal information; either for the operating system (i.e. Unix or Windows) or <span class="application">yabasic</span> itself.</p></li><li><p>The current time or date can be retrieved with (guess what !) <code class="function"><a href="#ref_time" title="time$">time$</a></code> and <code class="function"><a href="#ref_date" title="date$">date$</a></code>.</p></li></ul></div></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="chapter_topics_list"></a>Chapter 5. All commands and functions of <span class="application">yabasic</span> listed by topic</h2></div></div></div><div class="toc"><dl><dt><span class="sect1"><a href="#top_numbers">Number processing and conversion</a></span></dt><dt><span class="sect1"><a href="#top_conditions">Conditions and control structures</a></span></dt><dt><span class="sect1"><a href="#top_data">Data keeping and processing</a></span></dt><dt><span class="sect1"><a href="#top_strings">String processing</a></span></dt><dt><span class="sect1"><a href="#top_io">File operations and printing</a></span></dt><dt><span class="sect1"><a href="#top_sub">Subroutines and libraries</a></span></dt><dt><span class="sect1"><a href="#top_other">Other commands</a></span></dt><dt><span class="sect1"><a href="#top_graphics">Graphics and printing</a></span></dt></dl></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="top_numbers"></a>Number processing and conversion</h3></div></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_abs" title="abs()">abs()</a></span></dt><dd>
	    returns the absolute value of its numeric argument
	  </dd><dt><span class="term"><a href="#ref_acos" title="acos()">acos()</a></span></dt><dd>
	    returns the arcus cosine of its numeric argument
	  </dd><dt><span class="term"><a href="#ref_arithmetic_and" title="and()">and()</a></span></dt><dd>
	    the bitwise arithmetic <code class="function">and</code></dd><dt><span class="term"><a href="#ref_asin" title="asin()">asin()</a></span></dt><dd>
	    returns the arcus sine of its numeric argument
	  </dd><dt><span class="term"><a href="#ref_atan" title="atan()">atan()</a></span></dt><dd>
	    returns the arctangent of its numeric argument
	  </dd><dt><span class="term"><a href="#ref_bin" title="bin$()">bin$()</a></span></dt><dd>
	    converts a number into a sequence of binary digits
	  </dd><dt><span class="term"><a href="#ref_cos" title="cos()">cos()</a></span></dt><dd>
	    return the cosine of its single argument
	  </dd><dt><span class="term"><a href="#ref_dec" title="dec()">dec()</a></span></dt><dd>
	    convert a base 2 or base 16 number into decimal form
	  </dd><dt><span class="term"><a href="#ref_eor" title="eor()">eor()</a></span></dt><dd>
	    compute the bitwise <span class="emphasis"><em>exclusive or</em></span> of its two arguments
	  </dd><dt><span class="term"><a href="#ref_euler" title="euler">euler</a></span></dt><dd>
	    another name for the constant <code class="function">2.71828182864</code></dd><dt><span class="term"><a href="#ref_exp" title="exp()">exp()</a></span></dt><dd>
	    compute the exponential function of its single argument
	  </dd><dt><span class="term"><a href="#ref_frac" title="frac()">frac()</a></span></dt><dd>
	    return the fractional part of its numeric argument
	  </dd><dt><span class="term"><a href="#ref_int" title="int()">int()</a></span></dt><dd>
	    return the integer part of its single numeric argument
	  </dd><dt><span class="term"><a href="#ref_log" title="log()">log()</a></span></dt><dd>
	    compute the natural logarithm
	  </dd><dt><span class="term"><a href="#ref_max" title="max()">max()</a></span></dt><dd>
	    return the larger of its two arguments
	  </dd><dt><span class="term"><a href="#ref_min" title="min()">min()</a></span></dt><dd>
	    return the smaller of its two arguments
	  </dd><dt><span class="term"><a href="#ref_mod" title="mod()">mod()</a></span></dt><dd>
	    compute the remainder of a division
	  </dd><dt><span class="term"><a href="#ref_arithmetic_or" title="or()">or()</a></span></dt><dd>
	    arithmetic or, used for bit-operations
	  </dd><dt><span class="term"><a href="#ref_pi" title="pi">pi</a></span></dt><dd>
	    a constant with the value <code class="computeroutput">3.14159</code></dd><dt><span class="term"><a href="#ref_ran" title="ran()">ran()</a></span></dt><dd>
	    return a random number
	  </dd><dt><span class="term"><a href="#ref_sig" title="sig()">sig()</a></span></dt><dd>
	    return the sign of its argument
	  </dd><dt><span class="term"><a href="#ref_sin" title="sin()">sin()</a></span></dt><dd>
	    return the sine of its single argument
	  </dd><dt><span class="term"><a href="#ref_sqr" title="sqr()">sqr()</a></span></dt><dd>
	    compute the square of its argument
	  </dd><dt><span class="term"><a href="#ref_sqrt" title="sqrt()">sqrt()</a></span></dt><dd>
	    compute the square root of its argument
	  </dd><dt><span class="term"><a href="#ref_tan" title="tan()">tan()</a></span></dt><dd>
	    return the tangent of its argument
	  </dd><dt><span class="term"><a href="#ref_xor" title="xor()">xor()</a></span></dt><dd>
	    compute the exclusive or
	  </dd><dt><span class="term"><a href="#ref_pow" title="** or ^">** or ^</a></span></dt><dd>
	    raise its first argument to the power of its second
	  </dd></dl></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="top_conditions"></a>Conditions and control structures</h3></div></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_logical_and" title="and">and</a></span></dt><dd>
	    logical and, used in conditions
	  </dd><dt><span class="term"><a href="#ref_break" title="break">break</a></span></dt><dd>
	    breaks out of a switch statement or a loop
	  </dd><dt><span class="term"><a href="#ref_case" title="case">case</a></span></dt><dd>
	    mark the different cases within a <code class="function"><a href="#ref_switch" title="switch">switch</a></code>-statement
	  </dd><dt><span class="term"><a href="#ref_continue" title="continue">continue</a></span></dt><dd>
	    start the next iteration of a <code class="function">for</code>-, <code class="function">do</code>-, <code class="function">repeat</code>- or <code class="function">while</code>-loop
	  </dd><dt><span class="term"><a href="#ref_default" title="default">default</a></span></dt><dd>
	    mark the <span class="emphasis"><em>default</em></span>-branch within a <code class="function"><a href="#ref_switch" title="switch">switch</a></code>-statement
	  </dd><dt><span class="term"><a href="#ref_do" title="do">do</a></span></dt><dd>
	    start a (conditionless) <code class="function">do-loop</code></dd><dt><span class="term"><a href="#ref_else" title="else">else</a></span></dt><dd>
	    mark an alternative within an <code class="function">if</code>-statement
	  </dd><dt><span class="term"><a href="#ref_elsif" title="elsif">elsif</a></span></dt><dd>
	    starts an alternate condition within an <code class="function">if</code>-statement
	  </dd><dt><span class="term"><a href="#ref_end" title="end">end</a></span></dt><dd>
	    terminate your program
	  </dd><dt><span class="term"><a href="#ref_endif" title="endif">endif</a></span></dt><dd>
	    ends an <code class="function">if</code>-statement
	  </dd><dt><span class="term"><a href="#ref_false" title="false">false</a></span></dt><dd>
	    a constant with the value of 0
	  </dd><dt><span class="term"><a href="#ref_fi" title="fi">fi</a></span></dt><dd>
	    another name for <code class="function"><a href="#ref_endif" title="endif">endif</a></code></dd><dt><span class="term"><a href="#ref_for" title="for">for</a></span></dt><dd>
	    starts a <code class="function">for</code>-loop
	  </dd><dt><span class="term"><a href="#ref_gosub" title="gosub">gosub</a></span></dt><dd>
	    continue execution at another point within your program (and return later)
	  </dd><dt><span class="term"><a href="#ref_goto" title="goto">goto</a></span></dt><dd>
	    continue execution at another point within your program (and never come back)
	  </dd><dt><span class="term"><a href="#ref_if" title="if">if</a></span></dt><dd>
	    evaluate a condition and execute statements or not, depending on the result
	  </dd><dt><span class="term"><a href="#ref_label" title="label">label</a></span></dt><dd>
	    mark a specific location within your program for <code class="function">goto</code>, <code class="function">gosub</code> or <code class="function">restore</code></dd><dt><span class="term"><a href="#ref_loop" title="loop">loop</a></span></dt><dd>
	    marks the end of an infinite loop
	  </dd><dt><span class="term"><a href="#ref_next" title="next">next</a></span></dt><dd>
	    mark the end of a for loop
	  </dd><dt><span class="term"><a href="#ref_not" title="not">not</a></span></dt><dd>
	    negate an expression; can be written as <code class="function">!</code></dd><dt><span class="term"><a href="#ref_on_gosub" title="on gosub">on gosub</a></span></dt><dd>
	    jump to one of multiple <code class="function">gosub</code>-targets
	  </dd><dt><span class="term"><a href="#ref_on_goto" title="on goto">on goto</a></span></dt><dd>
	    jump to one of many <code class="function">goto</code>-targets
	  </dd><dt><span class="term"><a href="#ref_on_interrupt" title="on interrupt">on interrupt</a></span></dt><dd>
	    change reaction on keyboard interrupts
	  </dd><dt><span class="term"><a href="#ref_logical_or" title="logical or">logical or</a></span></dt><dd>
	    logical or, used in conditions
	  </dd><dt><span class="term"><a href="#ref_pause" title="pause">pause</a></span></dt><dd>
	    pause, sleep, wait for the specified number of seconds
	  </dd><dt><span class="term"><a href="#ref_repeat" title="repeat">repeat</a></span></dt><dd>
	    start a <code class="function">repeat</code>-loop
	  </dd><dt><span class="term"><a href="#ref_return" title="return">return</a></span></dt><dd>
	    return from a subroutine or a gosub
	  </dd><dt><span class="term"><a href="#ref_sleep" title="sleep">sleep</a></span></dt><dd>
	    pause, sleep, wait for the specified number of seconds
	  </dd><dt><span class="term"><a href="#ref_switch" title="switch">switch</a></span></dt><dd>
	    select one of many alternatives depending on a value
	  </dd><dt><span class="term"><a href="#ref_then" title="then">then</a></span></dt><dd>
	    tell the long from the short form of the <code class="function">if</code>-statement
	  </dd><dt><span class="term"><a href="#ref_true" title="true">true</a></span></dt><dd>
	    a constant with the value of 1
	  </dd><dt><span class="term"><a href="#ref_until" title="until">until</a></span></dt><dd>
	    end a <code class="function">repeat</code>-loop
	  </dd><dt><span class="term"><a href="#ref_wait" title="wait">wait</a></span></dt><dd>
	    pause, sleep, wait for the specified number of seconds
	  </dd><dt><span class="term"><a href="#ref_wend" title="wend">wend</a></span></dt><dd>
	    end a <code class="function"><a href="#ref_while" title="while">while</a></code>-loop
	  </dd><dt><span class="term"><a href="#ref_while" title="while">while</a></span></dt><dd>
	    start a <code class="function">while</code>-loop
	  </dd><dt><span class="term"><a href="#ref_colon" title=":">:</a></span></dt><dd>
	    separate commands from each other
	  </dd></dl></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="top_data"></a>Data keeping and processing</h3></div></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_arraydim" title="arraydim()">arraydim()</a></span></dt><dd>
	    returns the dimension of the array, which is passed as an <a href="#ref_array_references" title="References on arrays">array reference</a></dd><dt><span class="term"><a href="#ref_arraysize" title="arraysize()">arraysize()</a></span></dt><dd>
	    returns the size of a dimension of an array
	  </dd><dt><span class="term"><a href="#ref_data" title="data">data</a></span></dt><dd>
	    introduces a list of data-items
	  </dd><dt><span class="term"><a href="#ref_dim" title="dim">dim</a></span></dt><dd>
	    create an array prior to its first use
	  </dd><dt><span class="term"><a href="#ref_read" title="read">read</a></span></dt><dd>
	    read data from <code class="function">data</code>-statements
	  </dd><dt><span class="term"><a href="#ref_redim" title="redim">redim</a></span></dt><dd>
	    create an array prior to its first use. A synonym for <code class="function">dim</code></dd><dt><span class="term"><a href="#ref_restore" title="restore">restore</a></span></dt><dd>
	    reposition the <code class="function">data</code>-pointer
	  </dd></dl></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="top_strings"></a>String processing</h3></div></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_asc" title="asc()">asc()</a></span></dt><dd>
	    accepts a string and returns the position of its first character within the <span class="acronym">ascii</span> charset
	  </dd><dt><span class="term"><a href="#ref_chr" title="chr$()">chr$()</a></span></dt><dd>
	    accepts a number and returns the character at this position within the <span class="acronym">ascii</span> charset
	  </dd><dt><span class="term"><a href="#ref_glob" title="glob()">glob()</a></span></dt><dd>
	    check if a string matches a simple pattern
	  </dd><dt><span class="term"><a href="#ref_hex" title="hex$()">hex$()</a></span></dt><dd>
	    convert a number into hexadecimal
	  </dd><dt><span class="term"><a href="#ref_instr" title="instr()">instr()</a></span></dt><dd>
	    searches its second argument within the first; returns its position if found
	  </dd><dt><span class="term"><a href="#ref_left" title="left$()">left$()</a></span></dt><dd>
	    return (<span class="emphasis"><em>or change</em></span>) left end of a string
	  </dd><dt><span class="term"><a href="#ref_len" title="len()">len()</a></span></dt><dd>
	    return the length of a string
	  </dd><dt><span class="term"><a href="#ref_lower" title="lower$()">lower$()</a></span></dt><dd>
	    convert a string to lower case
	  </dd><dt><span class="term"><a href="#ref_ltrim" title="ltrim$()">ltrim$()</a></span></dt><dd>
	    trim spaces at the left end of a string
	  </dd><dt><span class="term"><a href="#ref_mid" title="mid$()">mid$()</a></span></dt><dd>
	    return (<span class="emphasis"><em>or change</em></span>) characters from within a string
	  </dd><dt><span class="term"><a href="#ref_right" title="right$()">right$()</a></span></dt><dd>
	    return (<span class="emphasis"><em>or change</em></span>) the right end of a string
	  </dd><dt><span class="term"><a href="#ref_split" title="split()">split()</a></span></dt><dd>
	    split a string into many strings
	  </dd><dt><span class="term"><a href="#ref_str" title="str$()">str$()</a></span></dt><dd>
	    convert a number into a string
	  </dd><dt><span class="term"><a href="#ref_token" title="token()">token()</a></span></dt><dd>
	    split a string into multiple strings
	  </dd><dt><span class="term"><a href="#ref_trim" title="trim$()">trim$()</a></span></dt><dd>
	    remove leading and trailing spaces from its argument
	  </dd><dt><span class="term"><a href="#ref_upper" title="upper$()">upper$()</a></span></dt><dd>
	    convert a string to upper case
	  </dd><dt><span class="term"><a href="#ref_val" title="val()">val()</a></span></dt><dd>
	    converts a string to a number
	  </dd></dl></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="top_io"></a>File operations and printing</h3></div></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_at" title="at()">at()</a></span></dt><dd>
	    can be used in the <code class="function">print</code>-command to place the output at a specified position
	  </dd><dt><span class="term"><a href="#ref_beep" title="beep">beep</a></span></dt><dd>
	    ring the bell within your computer; a synonym for <code class="function">bell</code></dd><dt><span class="term"><a href="#ref_bell" title="bell">bell</a></span></dt><dd>
	    ring the bell within your computer (just as <code class="function">beep</code>)
	  </dd><dt><span class="term"><a href="#ref_clear_screen" title="clear screen">clear screen</a></span></dt><dd>
	    erases the text window
	  </dd><dt><span class="term"><a href="#ref_close" title="close">close</a></span></dt><dd>
	    close a file, which has been opened before
	  </dd><dt><span class="term"><a href="#ref_close_printer" title="close printer">close printer</a></span></dt><dd>
	    stops printing of graphics
	  </dd><dt><span class="term"><a href="#ref_print_color" title="print color">print color</a></span></dt><dd>
	    print with color
	  </dd><dt><span class="term"><a href="#ref_print_colour" title="print colour">print colour</a></span></dt><dd>
	    see <code class="function"><a href="#ref_print_color" title="print color">print color</a></code></dd><dt><span class="term"><a href="#ref_eof" title="eof">eof</a></span></dt><dd>
	    check, if an open file contains data
	  </dd><dt><span class="term"><a href="#ref_getscreen" title="getscreen$()">getscreen$()</a></span></dt><dd>
	    returns a string representing a rectangular section of the text terminal
	  </dd><dt><span class="term"><a href="#ref_inkey" title="inkey$">inkey$</a></span></dt><dd>
	    wait, until a key is pressed
	  </dd><dt><span class="term"><a href="#ref_input" title="input">input</a></span></dt><dd>
	    read input from the user (or from a file) and assign it to a variable
	  </dd><dt><span class="term"><a href="#ref_line_input" title="line input">line input</a></span></dt><dd>
	    read in a whole line of text and assign it to a variable
	  </dd><dt><span class="term"><a href="#ref_open" title="open">open</a></span></dt><dd>
	    open a file
	  </dd><dt><span class="term"><a href="#ref_open_printer" title="open printer">open printer</a></span></dt><dd>
	    open printer for printing graphics
	  </dd><dt><span class="term"><a href="#ref_print" title="print">print</a></span></dt><dd>
	    Write to terminal or file
	  </dd><dt><span class="term"><a href="#ref_putscreen" title="putscreen">putscreen</a></span></dt><dd>
	    draw a rectangle of characters into the text terminal
	  </dd><dt><span class="term"><a href="#ref_reverse" title="reverse">reverse</a></span></dt><dd>
	    print reverse (background and foreground colors exchanged)
	  </dd><dt><span class="term"><a href="#ref_screen" title="screen">screen</a></span></dt><dd>
	    as <code class="function">clear screen</code> clears the text window
	  </dd><dt><span class="term"><a href="#ref_seek" title="seek()">seek()</a></span></dt><dd>
	    change the position within an open file
	  </dd><dt><span class="term"><a href="#ref_tell" title="tell">tell</a></span></dt><dd>
	    get the current position within an open file
	  </dd><dt><span class="term"><a href="#ref_using" title="using">using</a></span></dt><dd>
	    Specify the format for printing a number
	  </dd><dt><span class="term"><a href="#ref_hash" title="#">#</a></span></dt><dd>
	    either a comment or a marker for a file-number
	  </dd><dt><span class="term"><a href="#ref_at" title="at()">@</a></span></dt><dd>
	    synonymous to <code class="function"><a href="#ref_at" title="at()">at</a></code></dd><dt><span class="term"><a href="#ref_semicolon" title=";">;</a></span></dt><dd>
	    suppress the implicit newline after a <code class="function"><a href="#ref_print" title="print">print</a></code>-statement
	  </dd></dl></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="top_sub"></a>Subroutines and libraries</h3></div></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_end_sub" title="end sub">end sub</a></span></dt><dd>
	    ends a subroutine definition
	  </dd><dt><span class="term"><a href="#ref_export" title="export">export</a></span></dt><dd>
	    mark a function as globally visible
	  </dd><dt><span class="term"><a href="#ref_import" title="import">import</a></span></dt><dd>
	    import a library
	  </dd><dt><span class="term"><a href="#ref_local" title="local">local</a></span></dt><dd>
	    mark a variable as local to a subroutine
	  </dd><dt><span class="term"><a href="#ref_numparams" title="numparams">numparams</a></span></dt><dd>
	    return the number of parameters, that have been passed to a subroutine
	  </dd><dt><span class="term"><a href="#ref_return" title="return">return</a></span></dt><dd>
	    return from a subroutine or a gosub
	  </dd><dt><span class="term"><a href="#ref_static" title="static">static</a></span></dt><dd>
	    preserves the value of a variable between calls to a subroutine
	  </dd><dt><span class="term"><a href="#ref_step" title="step">step</a></span></dt><dd>
	    specifies the increment step in a for-loop
	  </dd><dt><span class="term"><a href="#ref_sub" title="sub">sub</a></span></dt><dd>
	    declare a user defined subroutine
	  </dd></dl></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="top_other"></a>Other commands</h3></div></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_bind" title="bind()">bind()</a></span></dt><dd>
	    Binds a <span class="application">yabasic</span>-program and the <span class="application">yabasic</span>-interpreter together into a <span class="emphasis"><em>standalone</em></span> program.
	  </dd><dt><span class="term"><a href="#ref_compile" title="compile">compile</a></span></dt><dd>
	    compile a string with <span class="acronym">yabasic</span>-code <span class="emphasis"><em>on the fly</em></span></dd><dt><span class="term"><a href="#ref_date" title="date$">date$</a></span></dt><dd>
	    returns a string with various components of the current date
	  </dd><dt><span class="term"><a href="#ref_doc" title="doc">doc</a></span></dt><dd>
	    special comment, which might be retrieved by the program itself
	  </dd><dt><span class="term"><a href="#ref_docu" title="docu$">docu$</a></span></dt><dd>
	    special array, containing the contents of all docu-statement within the program
	  </dd><dt><span class="term"><a href="#ref_error" title="error">error</a></span></dt><dd>
	    raise an error and terminate your program
	  </dd><dt><span class="term"><a href="#ref_execute" title="execute()">execute$()</a></span></dt><dd>
	    execute a user defined subroutine, which must return a string
	  </dd><dt><span class="term"><a href="#ref_execute" title="execute()">execute()</a></span></dt><dd>
	    execute a user defined subroutine, which must return a number
	  </dd><dt><span class="term"><a href="#ref_exit" title="exit">exit</a></span></dt><dd>
	    terminate your program
	  </dd><dt><span class="term"><a href="#ref_pause" title="pause">pause</a></span></dt><dd>
	    pause, sleep, wait for the specified number of seconds
	  </dd><dt><span class="term"><a href="#ref_peek" title="peek">peek</a></span></dt><dd>
	    retrieve various internal informations
	  </dd><dt><span class="term"><a href="#ref_peek2" title="peek$">peek$</a></span></dt><dd>
	    retrieve various internal string-informations
	  </dd><dt><span class="term"><a href="#ref_poke" title="poke">poke</a></span></dt><dd>
	    change selected internals of <span class="application">yabasic</span></dd><dt><span class="term"><a href="#ref_rem" title="rem">rem</a></span></dt><dd>
	    start a comment
	  </dd><dt><span class="term"><a href="#ref_sleep" title="sleep">sleep</a></span></dt><dd>
	    pause, sleep, wait for the specified number of seconds
	  </dd><dt><span class="term"><a href="#ref_system" title="system$()">system$()</a></span></dt><dd>
	    hand a statement over to your operating system and return its output
	  </dd><dt><span class="term"><a href="#ref_system2" title="system()">system()</a></span></dt><dd>
	    hand a statement over to your operating system and return its exitcode
	  </dd><dt><span class="term"><a href="#ref_time" title="time$">time$</a></span></dt><dd>
	    return a string containing the current time
	  </dd><dt><span class="term"><a href="#ref_to" title="to">to</a></span></dt><dd>
	    this keyword appears as part of other statements
	  </dd><dt><span class="term"><a href="#ref_wait" title="wait">wait</a></span></dt><dd>
	    pause, sleep, wait for the specified number of seconds
	  </dd><dt><span class="term"><a href="#ref_double_slash" title="//">//</a></span></dt><dd>
	    starts a comment
	  </dd><dt><span class="term"><a href="#ref_colon" title=":">:</a></span></dt><dd>
	    separate commands from each other
	  </dd></dl></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="top_graphics"></a>Graphics and printing</h3></div></div></div><div class="variablelist"><dl><dt><span class="term"><a href="#ref_backcolor" title="backcolor">backcolor</a></span></dt><dd>
	    specify the colour for subsequent drawing of the background
	  </dd><dt><span class="term"><a href="#ref_box" title="box">box</a></span></dt><dd>
	    draw a rectangle. A synonym for <code class="function">rectangle</code></dd><dt><span class="term"><a href="#ref_circle" title="circle">circle</a></span></dt><dd>
	    draws a circle in the graphic-window
	  </dd><dt><span class="term"><a href="#ref_clear" title="clear">clear</a></span></dt><dd>
	    Erase <code class="function">circle</code>s, <code class="function">rectangle</code>s or <code class="function">triangles</code>s
	  </dd><dt><span class="term"><a href="#ref_clear_window" title="clear window">clear window</a></span></dt><dd>
	    clear the graphic window and begin a new page, if printing is under way
	  </dd><dt><span class="term"><a href="#ref_close_curve" title="close curve">close curve</a></span></dt><dd>
	    close a curve, that has been drawn by the <code class="function">line</code>-command
	  </dd><dt><span class="term"><a href="#ref_close_window" title="close window">close window</a></span></dt><dd>
	    close the graphics-window
	  </dd><dt><span class="term"><a href="#ref_colour" title="colour">colour</a></span></dt><dd>
	    specify the colour for subsequent drawing
	  </dd><dt><span class="term"><a href="#ref_dot" title="dot">dot</a></span></dt><dd>
	    draw a dot in the graphic-window
	  </dd><dt><span class="term"><a href="#ref_fill" title="fill">fill</a></span></dt><dd>
	    draw a filled <code class="function">circle</code>s, <code class="function">rectangle</code>s or <code class="function">triangle</code>s
	  </dd><dt><span class="term"><a href="#ref_getbit" title="getbit$()">getbit$()</a></span></dt><dd>
	    return a string representing the bit pattern of a rectangle within the graphic window
	  </dd><dt><span class="term"><a href="#ref_line" title="line">line</a></span></dt><dd>
	    draw a line
	  </dd><dt><span class="term"><a href="#ref_mouseb" title="mouseb">mouseb</a></span></dt><dd>
	    extract the state of the mousebuttons from a string returned by <code class="function">inkey$</code></dd><dt><span class="term"><a href="#ref_mousemod" title="mousemod">mousemod</a></span></dt><dd>
	    return the state of the modifier keys during a mouseclick
	  </dd><dt><span class="term"><a href="#ref_mousex" title="mousex">mousex</a></span></dt><dd>
	    return the x-position of a mouseclick
	  </dd><dt><span class="term"><a href="#ref_mousey" title="mousey">mousey</a></span></dt><dd>
	    return the y-position of a mouseclick
	  </dd><dt><span class="term"><a href="#ref_new_curve" title="new curve">new curve</a></span></dt><dd>
	    start a new curve, that will be drawn with the <code class="function">line</code>-command
	  </dd><dt><span class="term"><a href="#ref_open_window" title="open window">open window</a></span></dt><dd>
	    open a graphic window
	  </dd><dt><span class="term"><a href="#ref_putbit" title="putbit">putbit</a></span></dt><dd>
	    draw a rectangle of pixels into the graphic window
	  </dd><dt><span class="term"><a href="#ref_rectangle" title="rectangle">rectangle</a></span></dt><dd>
	    draw a rectangle
	  </dd><dt><span class="term"><a href="#ref_triangle" title="triangle">triangle</a></span></dt><dd>
	    draw a triangle
	  </dd><dt><span class="term"><a href="#ref_text" title="text">text</a></span></dt><dd>
	    write text into your graphic-window
	  </dd><dt><span class="term"><a href="#ref_origin" title="window origin">window origin</a></span></dt><dd>
	    move the origin of a window
	  </dd></dl></div></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="chapter_ref_words"></a>Chapter 6. All commands and functions of <span class="application">yabasic</span> grouped alphabetically</h2></div></div></div><div class="toc"><dl><dt><span class="sect1"><a href="#ref_a">A</a></span></dt><dt><span class="sect1"><a href="#ref_b">B</a></span></dt><dt><span class="sect1"><a href="#ref_c">C</a></span></dt><dt><span class="sect1"><a href="#ref_d">D</a></span></dt><dt><span class="sect1"><a href="#ref_e">E</a></span></dt><dt><span class="sect1"><a href="#ref_f">F</a></span></dt><dt><span class="sect1"><a href="#ref_g">G</a></span></dt><dt><span class="sect1"><a href="#ref_h">H</a></span></dt><dt><span class="sect1"><a href="#ref_i">I</a></span></dt><dt><span class="sect1"><a href="#ref_l">L</a></span></dt><dt><span class="sect1"><a href="#ref_m">M</a></span></dt><dt><span class="sect1"><a href="#ref_n">N</a></span></dt><dt><span class="sect1"><a href="#ref_o">O</a></span></dt><dt><span class="sect1"><a href="#ref_p">P</a></span></dt><dt><span class="sect1"><a href="#ref_r">R</a></span></dt><dt><span class="sect1"><a href="#ref_s">S</a></span></dt><dt><span class="sect1"><a href="#ref_t">T</a></span></dt><dt><span class="sect1"><a href="#ref_u">U</a></span></dt><dt><span class="sect1"><a href="#ref_v">V</a></span></dt><dt><span class="sect1"><a href="#ref_w">W</a></span></dt><dt><span class="sect1"><a href="#ref_x">X</a></span></dt><dt><span class="sect1"><a href="#ref_special_characters">Special characters</a></span></dt><dt><span class="sect1"><a href="#reserved_word">Reserved Words</a></span></dt></dl></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_a"></a>A</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_abs">abs()</a></span><span class="refpurpose"> - returns the absolute value of its numeric argument</span></dt><dt><span class="refentrytitle"><a href="#ref_acos">acos()</a></span><span class="refpurpose"> - returns the arcus cosine of its numeric argument</span></dt><dt><span class="refentrytitle"><a href="#ref_logical_and">and</a></span><span class="refpurpose"> - logical and, used in conditions</span></dt><dt><span class="refentrytitle"><a href="#ref_arithmetic_and">and()</a></span><span class="refpurpose"> - the bitwise arithmetic and</span></dt><dt><span class="refentrytitle"><a href="#ref_arraydim">arraydim()</a></span><span class="refpurpose"> - returns the dimension of the array, which is passed as an array reference</span></dt><dt><span class="refentrytitle"><a href="#ref_arraysize">arraysize()</a></span><span class="refpurpose"> - returns the size of a dimension of an array</span></dt><dt><span class="refentrytitle"><a href="#ref_asc">asc()</a></span><span class="refpurpose"> - accepts a string and returns the position of its first character within the ascii charset</span></dt><dt><span class="refentrytitle"><a href="#ref_asin">asin()</a></span><span class="refpurpose"> - returns the arcus sine of its numeric argument</span></dt><dt><span class="refentrytitle"><a href="#ref_at">at()</a></span><span class="refpurpose"> - can be used in the print-command to place the output at a specified position</span></dt><dt><span class="refentrytitle"><a href="#ref_atan">atan()</a></span><span class="refpurpose"> - returns the arctangent of its numeric argument</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_abs"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>abs() — returns the absolute value of its numeric argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">y=abs(x)</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2515760"></a><h2>Description</h2><p>If the argument of the <code class="function">abs</code>-function is positive (e.g. 2) it is returned unchanged, if the argument is negative (e.g. -1) it is returned as a positive value (e.g. 1).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2515778"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print abs(-2),abs(2)
          </pre><p>This example will print <code class="computeroutput">2 2</code></p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2515803"></a><h2>See also</h2><p><a href="#ref_sig" title="sig()"><code class="function">sig</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_acos"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>acos() — returns the arcus cosine of its numeric argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">x=acos(angle)</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2515854"></a><h2>Description</h2><p><code class="function">acos</code> is the arcus cosine-function, i.e. the inverse of the <a href="#ref_cos" title="cos()"><code class="function">cos</code></a>-function. Or, more elaborate: It Returns the angle (in radian, not degree !), which, fed to the cosine-function will produce the argument passed to the <code class="function">acos</code>-function.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2515888"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print acos(0.5),acos(cos(pi))
          </pre><p>This example will print <code class="computeroutput">1.0472 3.14159</code> which are π/3 and π respectively.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2515912"></a><h2>See also</h2><p><a href="#ref_cos" title="cos()"><code class="function">cos</code></a>, <a href="#ref_asin" title="asin()"><code class="function">asin</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_logical_and"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>and — logical and, used in conditions</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (a and b) …
while (a and b) …
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2515979"></a><h2>Description</h2><p>Used in conditions (e.g within <code class="function"><a href="#ref_if" title="if">if</a></code>, <code class="function"><a href="#ref_while" title="while">while</a></code> or <code class="function"><a href="#ref_until" title="until">until</a></code>) to join two expressions. Returns <code class="constant">true</code>, if and only if its left and right argument are both <code class="constant">true</code> and <code class="constant">false</code> otherwise.</p><p>Note, that <a href="#ref_logical_shortcuts" title="Logical shortcuts"><span class="emphasis"><em>logical shortcuts</em></span></a> may take place.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516045"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a number" a
if (a&gt;=1 and a&lt;=9) print "your input is between 1 and 9"
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516065"></a><h2>See also</h2><p><a href="#ref_logical_or" title="logical or"><code class="function">or</code></a>,<a href="#ref_not" title="not"><code class="function">not</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_arithmetic_and"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>and() — the bitwise arithmetic <code class="function">and</code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=and(a,b)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516129"></a><h2>Description</h2><p>Used to compute the bitwise <code class="function">and</code> of both its argument. Both arguments are treated as binary numbers (i.e. a series of 0 and 1); a bit of the resulting value will then be 1, if both arguments have a 1 at this position in their binary representation.</p><p>Note, that both arguments are silently converted to integer values and that negative numbers have their own binary representation and may lead to unexpected results when passed to <code class="function">and</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516161"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print and(6,3)
          </pre><p>This will print <code class="computeroutput">2</code>. This result is clear, if you note, that the binary representation of 6 and 3 are 110 and 011 respectively; this will yield 010 in binary representation or 2 as decimal.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516189"></a><h2>See also</h2><p><a href="#ref_arithmetic_or" title="or()"><code class="function">or</code></a>, <a href="#ref_eor" title="eor()"><code class="function">eor</code></a> and <a href="#ref_not" title="not"><code class="function">not</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_arraydim"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>arraydim() — returns the dimension of the array, which is passed as an <a href="#ref_array_references" title="References on arrays">array reference</a></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">a=arraydim(b())</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516267"></a><h2>Description</h2><p>If you apply the <code class="literal">arraydim()</code>-function on a one-dimensional array (i.e. a vector) it will return <code class="computeroutput">1</code>, on a two-dimensional array (i.e. a matrix) it will return 2, and so on.</p><p>This is mostly used within subroutines, which expect an array among their parameters. Such subroutines tend to use the <code class="function">arraydim</code>-function to check, if the array which has been passed, has the right dimension. E.g. a subroutine to multiply two matrices may want to check, if it really is invoked with two 2-dimensional arrays.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516306"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
dim a(10,10),b(10)
print arraydim(a()),arraydim(b())
          </pre><p>This will print <code class="computeroutput">2 1</code>, which are the dimension of the arrays <code class="literal">a()</code> and <code class="literal">b()</code>. You may check out the function <a href="#ref_arraysize" title="arraysize()"><code class="function">arraysize</code></a> for a full-fledged example.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516355"></a><h2>See also</h2><p><a href="#ref_arraysize" title="arraysize()"><code class="function">arraysize</code></a> and <a href="#ref_dim" title="dim"><code class="function">dim</code></a>.</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_arraysize"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>arraysize() — returns the size of a dimension of an array</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">x=arraysize(a(),b)</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516417"></a><h2>Description</h2><p>The <code class="function">arraysize</code>-function computes the size of a specified dimension of a specified array. Here, <span class="emphasis"><em>size</em></span> stands for the maximum number, that may be used as an index for this array. The first argument to this function must be an <a href="#ref_array_references" title="References on arrays">reference to an array</a>, the second one specifies, which of the multiple dimensions of the array should be taken to calculate the size.</p><p>An Example involving subroutines: Let's say, an array has been declared as <code class="literal">dim a(10,20)</code> (that is a two-dimensional array or a matrix). If this array is passed as an <a href="#ref_array_references" title="References on arrays">array reference</a> to a subroutine, this sub will not know, what sort of array has been passed. With the <code class="function">arraydim</code>-function the sub will be able to find the dimension of the array, with the <code class="function">arraysize</code>-function it will be able to find out the size of this array in its two dimensions, which will be 10 and 20 respectively.</p><p>Our sample array is two dimensional; if you envision it as a matrix this matrix has 10 lines and 20 columns (see the <code class="function">dim</code>-statement above. To state it more formally: The first dimension (lines) has a size of 10, the second dimension (columns) has a size of 20; these numbers are those returned by <code class="literal">arraysize(a(),1)</code> and <code class="literal">arraysize(a(),2)</code> respectively. Refer to the example below for a typical usage.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516513"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">

rem
rem  This program adds two matrices elementwise.
rem

dim a(10,20),b(10,20),c(10,20)

rem  initialization of the arrays a() and b() 
for y=1 to 10:for x=1 to 20
   a(y,x)=int(ran(4)):b(y,x)=int(ran(4))
next x:next y

matadd(a(),b(),c())

print "Result:"
for x=1 to 20
   for y=10 to 1 step -1
      print c(y,x)," ";
   next y
   print
next x

sub matadd(m1(),m2(),r())

   rem  This sub will add the matrices m1() and m2()
   rem  elementwise and store the result within r()
   rem  This is not very useful but easy to implement.
   rem  However, this sub excels in checking its arguments
   rem  with arraydim() and arraysize()

   local x:local y
   
   if (arraydim(m1())&lt;&gt;2 or arraydim(m2())&lt;&gt;2 or arraydim(r())&lt;&gt;2) then
      error "Need two dimensional arrays as input"
   endif

   y=arraysize(m1(),1):x=arraysize(m1(),2)
   if (arraysize(m2(),1)&lt;&gt;y or arraysize(m2(),2)&lt;&gt;x) then
      error "The two matrices cannot be added elementwise"
   endif

   if (arraysize(r(),1)&lt;&gt;y or arraysize(r(),2)&lt;&gt;x) then
      error "The result cannot be stored in the third argument"
   endif

   local xx:local yy
   for xx=1 to x
      for yy=1 to y
         r(yy,xx)=m1(yy,xx)+m2(yy,xx)
      next yy
   next xx

 end sub

          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516551"></a><h2>See also</h2><p><a href="#ref_arraydim" title="arraydim()"><code class="function">arraydim</code></a> and <a href="#ref_dim" title="dim"><code class="function">dim</code></a>.</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_asc"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>asc() — accepts a string and returns the position of its first character within the <span class="acronym">ascii</span> charset</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">a=asc(char$)</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516617"></a><h2>Description</h2><p>The <code class="function">asc</code>-function accepts a string, takes its first character and looks it up within the <span class="acronym">ascii</span>-charset; this position will be returned. The <code class="function">asc</code>-function is the opposite of the <code class="function"><a href="#ref_chr" title="chr$()">chr$</a></code>-function. There are valid uses for <code class="function">asc</code>, however, comparing strings (i.e. to bring them into alphabetical sequence) is <span class="emphasis"><em>not</em></span> among them; in such many cases you might consider to compare strings directly with <code class="literal">&lt;</code>, <code class="literal">=</code> and <code class="literal">&gt;</code> (rather than converting a string to a number and comparing this number).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516686"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a letter between 'a' and 'y': " a$
if (a$&lt;"a" or a$&gt;"y") print a$," is not in the proper range":end
print "The letter after ",a$," is ",chr$(asc(a$)+1)
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516709"></a><h2>See also</h2><p><a href="#ref_chr" title="chr$()"><code class="function">chr$</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_asin"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>asin() — returns the arcus sine of its numeric argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">angle=asin(x)</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516760"></a><h2>Description</h2><p><code class="function">acos</code> is the arcus sine-function, i.e. the inverse of the <a href="#ref_sin" title="sin()"><code class="function">sin</code></a>-function. Or, more elaborate: It Returns the angle (in radian, not degree !), which, fed to the sine-function will produce the argument passed to the <code class="function">asin</code>-function.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516794"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print asin(0.5),asin(sin(pi))
          </pre><p>This will print <code class="computeroutput">0.523599 -2.06823e-13</code> which is π and almost 0 respectively.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516821"></a><h2>See also</h2><p><a href="#ref_sin" title="sin()"><code class="function">sin</code></a>, <a href="#ref_acos" title="acos()"><code class="function">acos</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_at"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>at() — can be used in the <code class="function">print</code>-command to place the output at a specified position</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
…
print at(a,b)
print @(a,b)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516889"></a><h2>Description</h2><p>The <code class="function">at</code>-clause takes two numeric arguments (e.g. <code class="literal">at(2,3)</code>) and can be inserted after the <code class="literal">print</code>-keyword. <code class="literal">at()</code> can be used only if <a href="#ref_clear_screen" title="clear screen"><code class="function">clear screen</code></a> has been executed at least once within the program (otherwise you will get an error).</p><p>The two numeric arguments of the <code class="function">at</code>-function may range from 0 to the width of your terminal minus 1, and from 0 to the height of your terminal minus 1; if any argument exceeds these values, it will be truncated accordingly. However, <span class="application">yabasic</span> has no influence on the size of your terminal (80x25 is a common, but not mandatory), the size of your terminal and the maximum values acceptable within the <code class="function">at</code>-clause may vary. To get the size of your terminal you may use the <a href="#ref_peek" title="peek"><code class="function">peek</code></a>-function: <code class="literal">peek("screenwidth")</code> returns the width of your terminal and <code class="literal">peek("screenheight")</code> its height.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2516987"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
maxx=peek("screenwidth")-1:maxy=peek("screenheight")-1
for x=0 to maxx
  print at(x,maxy*(0.5+sin(2*pi*x/maxx)/2)) "*"
next x
          </pre><p>This example plots a full period of the sine-function across the screen.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517009"></a><h2>See also</h2><p><a href="#ref_print" title="print"><code class="function">print</code></a>, <a href="#ref_clear_screen" title="clear screen"><code class="function">clear screen</code></a>, <a href="#ref_print_color" title="print color"><code class="function">color</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_atan"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>atan() — returns the arctangent of its numeric argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
angle=atan(a,b)
angle=atan(a)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517081"></a><h2>Description</h2><p><code class="function">atan</code> is the arctangent-function, i.e. the inverse of the <a href="#ref_tan" title="tan()"><code class="function">tan</code></a>-function. Or, more elaborate: It Returns the angle (in radian, not degree !), which, fed to the <code class="function">tan</code>-function will produce the argument passed to the <code class="function">atan</code>-function.</p><p>The <code class="function">atan</code>-function has a second form, which accepts two arguments: <code class="function">atan(a,b)</code> which is (mostly) equivalent to <code class="function">atan(a/b)</code> <span class="emphasis"><em>except</em></span> for the fact, that the two-argument-form returns an angle in the range -π to π, whereas the one-argument-form returns an angle in the range -π/2 to π/2. To understand this you have to be good at math.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517151"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print atan(1),atan(tan(pi)),atan(-0,-1),atan(-0,1)
          </pre><p>This will print <code class="computeroutput">0.463648 2.06823e-13 -3.14159 3.14159</code> which is π/4, almost 0, -π and π respectively.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517178"></a><h2>See also</h2><p><code class="function"><a href="#ref_tan" title="tan()">tan</a></code>, <code class="function"><a href="#ref_sin" title="sin()">sin</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_b"></a>B</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_backcolor">backcolor</a></span><span class="refpurpose"> - change color for background of graphic window</span></dt><dt><span class="refentrytitle"><a href="#ref_backcolour">backcolour</a></span><span class="refpurpose"> - see backcolor</span></dt><dt><span class="refentrytitle"><a href="#ref_beep">beep</a></span><span class="refpurpose"> - ring the bell within your computer; a synonym for bell</span></dt><dt><span class="refentrytitle"><a href="#ref_bell">bell</a></span><span class="refpurpose"> - ring the bell within your computer (just as beep)</span></dt><dt><span class="refentrytitle"><a href="#ref_bin">bin$()</a></span><span class="refpurpose"> - converts a number into a sequence of binary digits</span></dt><dt><span class="refentrytitle"><a href="#ref_bind">bind()</a></span><span class="refpurpose"> - Binds a yabasic-program and the yabasic-interpreter together into a standalone program.</span></dt><dt><span class="refentrytitle"><a href="#ref_box">box</a></span><span class="refpurpose"> - draw a rectangle. A synonym for rectangle</span></dt><dt><span class="refentrytitle"><a href="#ref_break">break</a></span><span class="refpurpose"> - breaks out of a switch statement or a loop</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_backcolor"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>color — change color for background of graphic window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
backcolour red,green,blue
backcolour "red,green,blue"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517252"></a><h2>Description</h2><p>Change the color, that becomes visible, if any portion of the window is erased, e.g. after <code class="function"><a href="#ref_clear_window" title="clear window">clear window</a></code> or <code class="function"><a href="#ref_clear" title="clear">clear line</a></code>. Note however, that parts of the window, that display the old background color will not change.</p><p>
As with the <code class="function"><a href="#ref_color" title="color">color</a></code>-command, the new background color can either be specified as a triple of three numbers or as a single string, that contains those three numbers sperated by commas.
</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517304"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 255,255
for x=10 to 235 step 10:for y=10 to 235 step 10
  	backcolour x,y,0
	clear window
	sleep 1
next y:next x
          </pre><p>This changes the background colour of the graphic window repeatedly and clears it every time, so that it is filled with the new background colour.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517328"></a><h2>See also</h2><p><code class="function"><a href="#ref_open_window" title="open window">open window</a></code>, <code class="function"><a href="#ref_color" title="color">color</a></code>, <code class="function"><a href="#ref_line" title="line">line</a></code>, <code class="function"><a href="#ref_rectangle" title="rectangle">rectangle</a></code>, <code class="function"><a href="#ref_triangle" title="triangle">triangle</a></code>, <code class="function"><a href="#ref_circle" title="circle">circle</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_backcolour"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>backcolour — see <code class="function"><a href="#ref_backcolor" title="backcolor">backcolor</a></code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
backcolour red,green,blue
backcolour "red,green,blue"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517439"></a><h2>See also</h2><p><code class="function"><a href="#ref_print_color" title="print color">color</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_beep"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>beep — ring the bell within your computer; a synonym for <code class="function">bell</code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">beep</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517495"></a><h2>Description</h2><p>The <code class="function">bell</code>-command rings the bell within your computer once. This command is <span class="emphasis"><em>not</em></span> a sound-interface, so you can neither vary the length or the height of the sound (technically, it just prints <code class="literal">\a</code>). <code class="function">bell</code> is exactly the same as <code class="function"><a href="#ref_beep" title="beep">beep</a></code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517539"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
beep:print "This is a problem ..."
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517555"></a><h2>See also</h2><p><code class="function"><a href="#ref_beep" title="beep">beep</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_bell"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>bell — ring the bell within your computer (just as <code class="function">beep</code>)</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">bell</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517612"></a><h2>Description</h2><p>The <code class="function">beep</code>-command rings the bell within your computer once. <code class="function">beep</code> is a synonym for <code class="function"><a href="#ref_bell" title="bell">bell</a></code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517645"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "This is a problem ...":beep
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517661"></a><h2>See also</h2><p><code class="function"><a href="#ref_bell" title="bell">bell</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_bin"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>bin$() — converts a number into a sequence of binary digits</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">hexadecimal$=bin$(decimal)</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517712"></a><h2>Description</h2><p>The <code class="function">bin$</code>-function takes a single numeric argument an converts it into a string of binary digits (i.e. zeroes and ones). If you pass a negative number to <code class="function">bin$</code>, the resulting string will be preceded by a '-'.</p><p>If you want to convert the other way around (i.e. from binary to decimal) you may use the <code class="function"><a href="#ref_dec" title="dec()">dec</a></code>-function.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517752"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 100
  print bin$(a)
next a
          </pre><p>This example prints the binary representation of all digits between 1 and 100.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517773"></a><h2>See also</h2><p><code class="function"><a href="#ref_hex" title="hex$()">hex$</a></code>, <code class="function"><a href="#ref_dec" title="dec()">dec</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_bind"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>bind() — Binds a <span class="application">yabasic</span>-program and the <span class="application">yabasic</span>-interpreter together into a <span class="emphasis"><em>standalone</em></span> program.</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">bind("foo.exe")</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517849"></a><h2>Description</h2><p>The <code class="function">bind</code>-command combines your own <span class="application">yabasic</span>-program (plus all the libraries it does <code class="function">import</code>) and the interpreter by copying them into a new file, whose name is passed as an argument. This new program may then be executed on any computer, even if it does not have <span class="application">yabasic</span> installed.</p><p>Please see the section about <a href="#ref_standalone" title="Creating a standalone program from your yabasic-program">creating a <span class="emphasis"><em>standalone</em></span>-program</a> for details.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517902"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
if (!peek("isbound")) then
  bind "foo"
  print "Successfully created the standalone executable 'foo' !"
  exit
endif

print "Hello World !"
          </pre><p>This example creates a standalone program <code class="filename">foo</code> from itself.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2517930"></a><h2>See also</h2><p>The section about <a href="#ref_standalone" title="Creating a standalone program from your yabasic-program">creating a <span class="emphasis"><em>standalone</em></span>-program</a>, the <a href="#ref_peek" title="peek"><code class="function">peek</code></a>-function and the commandline options for <a href="#unix_options">Unix</a> and <a href="#windows_options">Windows</a>.</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_box"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>box — draw a rectangle. A synonym for <code class="function">rectangle</code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
See the <code class="function"><a href="#ref_rectangle" title="rectangle">rectangle</a></code>-command.
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518026"></a><h2>Description</h2><p>The <code class="function">box</code>-command does exactly the same as the <code class="function"><a href="#ref_rectangle" title="rectangle">rectangle</a></code>-command; it is just a <span class="emphasis"><em>synonym</em></span>. Therefore you should refer to the entry for the <code class="function"><a href="#ref_rectangle" title="rectangle">rectangle</a></code>-command for further information.</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_break"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>break — breaks out of a switch statement or a loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">break</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518102"></a><h2>Description</h2><p><code class="function">break</code> transfers control immediately outside the enclosing loop or switch statement. This is the preferred way of leaving a such a statement (rather than <code class="function">goto</code>, which is still possible in most cases).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518125"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 10
  break
  print "Hi"
next a

while(1)
  break
  print "Hi"
wend

repeat
  break
  print "Hi"
until(0)

switch 1
case 1:break
case 2:case 3:print "Hi"
end switch
          </pre><p>This example prints nothing at all, because each of the loops (and the <code class="function">switch</code>-statement) does an immediate <code class="function">break</code> (before it could print any "Hi").</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518161"></a><h2>See also</h2><p><code class="function"><a href="#ref_for" title="for">for</a></code>, <code class="function"><a href="#ref_while" title="while">while</a></code>, <code class="function"><a href="#ref_repeat" title="repeat">repeat</a></code> and <code class="function"><a href="#ref_switch" title="switch">switch</a></code>.</p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_c"></a>C</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_case">case</a></span><span class="refpurpose"> - mark the different cases within a switch-statement</span></dt><dt><span class="refentrytitle"><a href="#ref_chr">chr$()</a></span><span class="refpurpose"> - accepts a number and returns the character at this position within the ascii charset</span></dt><dt><span class="refentrytitle"><a href="#ref_circle">circle</a></span><span class="refpurpose"> - draws a circle in the graphic-window</span></dt><dt><span class="refentrytitle"><a href="#ref_clear">clear</a></span><span class="refpurpose"> - Erase circles, rectangles or triangles</span></dt><dt><span class="refentrytitle"><a href="#ref_clear_screen">clear screen</a></span><span class="refpurpose"> - erases the text window</span></dt><dt><span class="refentrytitle"><a href="#ref_clear_window">clear window</a></span><span class="refpurpose"> - clear the graphic window and begin a new page, if printing is under way</span></dt><dt><span class="refentrytitle"><a href="#ref_close">close</a></span><span class="refpurpose"> - close a file, which has been opened before</span></dt><dt><span class="refentrytitle"><a href="#ref_close_curve">close curve</a></span><span class="refpurpose"> - close a curve, that has been drawn by the line-command</span></dt><dt><span class="refentrytitle"><a href="#ref_close_printer">close printer</a></span><span class="refpurpose"> - stops printing of graphics</span></dt><dt><span class="refentrytitle"><a href="#ref_close_window">close window</a></span><span class="refpurpose"> - close the graphics-window</span></dt><dt><span class="refentrytitle"><a href="#ref_color">color</a></span><span class="refpurpose"> - change color for any subsequent drawing-command</span></dt><dt><span class="refentrytitle"><a href="#ref_colour">colour</a></span><span class="refpurpose"> - see color</span></dt><dt><span class="refentrytitle"><a href="#ref_compile">compile</a></span><span class="refpurpose"> - compile a string with yabasic-code on the fly</span></dt><dt><span class="refentrytitle"><a href="#ref_continue">continue</a></span><span class="refpurpose"> - start the next iteration of a for-, do-, repeat- or while-loop</span></dt><dt><span class="refentrytitle"><a href="#ref_cos">cos()</a></span><span class="refpurpose"> - return the cosine of its single argument</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_case"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>case — mark the different cases within a <code class="function"><a href="#ref_switch" title="switch">switch</a></code>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
switch a
  case 1
  case 2
  …
end switch

…

switch a$
  case "a"
  case "b"
  …
end switch
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518268"></a><h2>Description</h2><p>Please see the <code class="function"><a href="#ref_switch" title="switch">switch</a></code>-statement.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518288"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input a
switch(a)
  case 1:print "one":break
  case 2:print "two":break
  default:print "more"
end switch
          </pre><p>Depending on your input (a number is expected) this code will print <code class="computeroutput">one</code> or <code class="computeroutput">two</code> or otherwise <code class="computeroutput">more</code>.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518329"></a><h2>See also</h2><p><code class="function"><a href="#ref_switch" title="switch">switch</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_chr"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>chr$() — accepts a number and returns the character at this position within the <span class="acronym">ascii</span> charset</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">character$=chr$(ascii)</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518384"></a><h2>Description</h2><p>The <code class="function">chr$</code>-function is the opposite of the <code class="function"><a href="#ref_asc" title="asc()">asc</a></code>-function. It looks up and returns the character at the given position within the <span class="acronym">ascii</span>-charset. It's typical use is to construct <span class="emphasis"><em>nonprintable</em></span> characters which do not occur on your keyboard.</p><p>Nevertheless you won't use <code class="function">chr$</code> as often as you might think, because the most important nonprintable characters can be constructed using <span class="emphasis"><em><a href="#ref_escape_sequences" title="Escape-sequences">escape-sequences</a></em></span> using the \-character (e.g. you might use \n instead of <code class="function">chr$(10)</code> wherever you want to use the newline-character).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518449"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "a",chr$(10),"b"
          </pre><p>This will print the letters 'a' and 'b' in different lines because of the intervening newline-character, which is returned by <code class="function">chr$(10)</code>.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518477"></a><h2>See also</h2><p><code class="function"><a href="#ref_asc" title="asc()">asc</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_circle"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>circle — draws a circle in the graphic-window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
circle x,y,r
clear circle x,y,r
fill circle x,y,r
clear fill circle x,y,r
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518528"></a><h2>Description</h2><p>The <code class="function">circle</code>-command accepts three parameters: The x- and y-coordinates of the center and the radius of the circle.</p><p>Some more observations related with the <code class="function">circle</code>-command:</p><div class="itemizedlist"><ul type="disc"><li><p>The graphic-window must have been opened already.</p></li><li><p>The circle may well extend over the boundaries of the window.</p></li><li><p>If you have issued <code class="function"><a href="#ref_open_printer" title="open printer">open printer</a></code> before, the circle
will finally appear in the printed hard copy of the window.</p></li><li><p><code class="function">fill circle</code> will draw a filled (with black ink) circle.</p></li><li><p><code class="function">clear circle</code> will erase (or clear) the outline of the circle.</p></li><li><p><code class="function">clear fill circle</code> or <code class="function">fill clear circle</code> will erase the full area of the circle.</p></li></ul></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518635"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200

for n=1 to 2000
  x=ran(200)
  y=ran(200)
  fill circle x,y,10
  clear fill circle x,y,8
next n
          </pre><p>This code will open a window and draw 2000 overlapping circles within. Each circle is drawn in two steps: First it is filled with black ink (<code class="function">fill circle x,y,10</code>), then most of this circle is erased again (<code class="function">clear fill circle x,y,8</code>). As a result each circle is drawn with an opaque white interior and a 2-pixel outline (2-pixel, because the radii differ by two).</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518674"></a><h2>See also</h2><p><code class="function"><a href="#ref_open_window" title="open window">open window</a></code>, <code class="function"><a href="#ref_open_printer" title="open printer">open printer</a></code>, <code class="function"><a href="#ref_line" title="line">line</a></code>, <code class="function"><a href="#ref_rectangle" title="rectangle">rectangle</a></code>, <code class="function"><a href="#ref_triangle" title="triangle">triangle</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_clear"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>clear — Erase <code class="function">circle</code>s, <code class="function">rectangle</code>s or <code class="function">triangle</code>s</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear rectangle 10,10,90,90
clear fill circle 50,50,20
clear triangle 10,10,20,20,50,30
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518784"></a><h2>Description</h2><p>May be used within the <code class="function"><a href="#ref_circle" title="circle">circle</a></code>, <code class="function"><a href="#ref_rectangle" title="rectangle">rectangle</a></code> or <code class="function"><a href="#ref_triangle" title="triangle">triangle</a></code> command and causes these shapes to be erased (i.e. be drawn in the colour of the background).</p><p><code class="function">fill</code> can be used in conjunction with and wherever the <code class="function"><a href="#ref_fill" title="fill">fill</a></code>-clause may appear. Used alone, <code class="function">clear</code> will erase the outline (not the interior) of the shape (circle, rectangle or triangle); together with <code class="function">fill</code> the whole shape (including its interior) is erased.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518861"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
fill circle 100,100,50
clear fill rectangle 10,10,90,90
          </pre><p>This opens a window and draws a pacman-like figure.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518882"></a><h2>See also</h2><p><code class="function"><a href="#ref_clear" title="clear">clear</a></code>, <code class="function"><a href="#ref_circle" title="circle">circle</a></code>, <code class="function"><a href="#ref_rectangle" title="rectangle">rectangle</a></code>, <code class="function"><a href="#ref_triangle" title="triangle">triangle</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_clear_screen"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>clear screen — erases the text window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2518964"></a><h2>Description</h2><p><code class="function">clear screen</code> erases the text window (the window where the output of <code class="function">print</code> appears).</p><p>It must be issued at least once, before some advanced screen-commands (e.g. <code class="function">print at</code> or <code class="function">inkey$</code>) may be called; this requirement is due to some limitations of the <code class="systemitem">curses</code>-library, which is used by <span class="application">yabasic</span> under <span class="acronym">Unix</span> for some commands.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519020"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
print "Please press a key : ";
a$=inkey$
print a$
          </pre><p>The <code class="function">clear screen</code> command is essential here; if it would be omitted, <span class="application">yabasic</span> would issue an error ("<code class="computeroutput">need to call 'clear screen' first</code>") while trying to execute the <code class="function">inkey$</code>-function.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519066"></a><h2>See also</h2><p><code class="function"><a href="#ref_inkey" title="inkey$">inkey$</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_clear_window"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>clear window — clear the graphic window and begin a new page, if printing is under way</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">clear window</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519118"></a><h2>Description</h2><p><code class="function">clear window</code> clears the graphic window. If you have started printing the graphic via <code class="function"><a href="#ref_open_printer" title="open printer">open printer</a></code>, the <code class="function">clear window</code>-command starts a new page as well.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519151"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
open printer "t.ps"

for a=1 to 10
if (a&gt;1) clear window
text 100,100,"Hallo "+str$(a)
next a

close printer
close window
          </pre><p>This example prints 10 pages, with the text "Hello 1", "Hello 2", … and so on. The <code class="function">clear screen</code>-command clears the graphics window and starts a new page.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519182"></a><h2>See also</h2><p><code class="function"><a href="#ref_open_window" title="open window">open window</a></code>, <code class="function"><a href="#ref_open_printer" title="open printer">open printer</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_close"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>close — close a file, which has been opened before</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
close filenum
close # filenum
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519244"></a><h2>Description</h2><p>The <code class="function">close</code>-command closes an open file. You should issue this command as soon as you are done with reading from or writing to a file.</p><p></p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519264"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open "my.data" for reading as 1
input #1 a
print a
close 1
          </pre><p>This program opens the file <code class="systemitem">"my.data"</code>, reads a number from it, prints this number and closes the file again.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519292"></a><h2>See also</h2><p><code class="function"><a href="#ref_open" title="open">open</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_close_curve"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>close curve — close a curve, that has been drawn by the <code class="function">line</code>-command</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
new curve
line to x1,y1
…
close curve
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519350"></a><h2>Description</h2><p>The <code class="function">close curve</code>-command closes a sequence of lines, that has been drawn by repeated <code class="function">line to</code>-commands.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519373"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
new curve
line to 100,50
line to 150,150
line to 50,150
close curve
          </pre><p>This example draws a triangle: The three <code class="function">line to</code>-commands draw two lines; the final line is however not drawn explicitly, but drawn by the <code class="function">close curve</code>-command.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519408"></a><h2>See also</h2><p><code class="function"><a href="#ref_line" title="line">line</a></code>, <code class="function"><a href="#ref_new_curve" title="new curve">new curve</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_close_printer"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>close printer — stops printing of graphics</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">close printer</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519469"></a><h2>Description</h2><p>The <code class="function">close printer</code>-command ends the printing graphics. Between <code class="function"><a href="#ref_open_printer" title="open printer">open printer</a></code> and <code class="function">close printer</code> everything you draw (e.g. circles, lines …) is sent to your printer. <code class="function">close printer</code> puts an end to printing and will make your printer eject the page.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519510"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
open printer
circle 100,100,50
close printer
close window
          </pre><p>As soon as <code class="function">close printer</code> is executed, your printer will eject a page with a circle on it.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519538"></a><h2>See also</h2><p><code class="function"><a href="#ref_open_printer" title="open printer">open printer</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_close_window"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>close window — close the graphics-window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">close window</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519590"></a><h2>Description</h2><p>The <code class="function">close window</code>-command closes the graphics-window, i.e. it makes it disappear from your screen. It includes an implicit <code class="function">close printer</code>, if a printer has been opened previously.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519614"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
circle 100,100,50
close window
          </pre><p>This example will open a window, draw a circle and close the window again; all this without any pause or delay, so the window will be closed before you may regard the circle..</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519636"></a><h2>See also</h2><p><code class="function"><a href="#ref_open_printer" title="open printer">open window</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_color"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>color — change color for any subsequent drawing-command</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
colour red,green,blue
colour "red,green,blue"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519689"></a><h2>Description</h2><p>Change the color, in which lines, dots, circles, rectangles or triangles are drawn. The <code class="function">color</code>-command accepts three numbers in the range 0 … 255 (as in the first line of the synopsis above). Those numbers specify the intensity for the primary colors red, green and blue respectively. As an example <code class="function">255,0,0</code> is red and <code class="function">255,255,0</code> is yellow.</p><p>
Alternatively you may specify the color with a single string (as in the second line of the synopsis above); this string should contain three numbers, separated by commas. As an example <code class="function">"255,0,255"</code> would be violet. Using this variant of the <code class="function">colour</code>-command, you may use symbolic names for colours:
</p><pre class="programlisting">
open window 100,100
yellow$="255,255,0"
color yellow$
text 50,50,"Hallo"
</pre><p>
, which reads much clearer.
</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519752"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 255,255
for x=10 to 235 step 10:for y=10 to 235 step 10
  	colour x,y,0
  	fill rectangle x,y,x+10,y+10
next y:next x
          </pre><p>This fills the window with colored rectangles. However, none of the used colours contains any shade of blue, because the <code class="function">color</code>-command has always 0 as a third argument.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519782"></a><h2>See also</h2><p><code class="function"><a href="#ref_open_window" title="open window">open window</a></code>, <code class="function"><a href="#ref_backcolor" title="backcolor">backcolor</a></code>, <code class="function"><a href="#ref_line" title="line">line</a></code>, <code class="function"><a href="#ref_rectangle" title="rectangle">rectangle</a></code>, <code class="function"><a href="#ref_triangle" title="triangle">triangle</a></code>, <code class="function"><a href="#ref_circle" title="circle">circle</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_colour"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>colour — see <code class="function"><a href="#ref_color" title="color">color</a></code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
colour red,green,blue
colour "red,green,blue"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519893"></a><h2>See also</h2><p><code class="function"><a href="#ref_print_color" title="print color">color</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_compile"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>compile — compile a string with <span class="acronym">yabasic</span>-code <span class="emphasis"><em>on the fly</em></span></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">compile(code$)</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519950"></a><h2>Description</h2><p>This is an advanced command (closely related with the <code class="function"><a href="#ref_execute" title="execute()">execute</a></code>-command). It allows you to compile a string of yabasic-code (which is the only argument). Afterwards the compiled code is a normal part of your program.</p><p>Note, that there is no way to <span class="emphasis"><em>remove</em></span> the compiled code.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2519981"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
compile("sub mysub(a):print a:end sub")
mysub(2)
          </pre><p>This example creates a function named <code class="function">mysub</code>, which simply prints its single argument.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520008"></a><h2>See also</h2><p><code class="function"><a href="#ref_execute" title="execute()">execute</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_continue"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>continue — start the next iteration of a <code class="function">for</code>-, <code class="function">do</code>-, <code class="function">repeat</code>- or <code class="function">while</code>-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">continue</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520082"></a><h2>Description</h2><p>You may use <code class="function">continue</code> within any loop to start the next iteration immediately. Depending on the type of the loop, the loop-condition will or will not be checked. Especially: <code class="function">for</code>- and <code class="function">while</code>-loops will evaluate their respective conditions, <code class="function">do</code>- and <code class="function">repeat</code>-loops will not.</p><p class="remark"><i><span class="remark">Remark: Another way to change the flow of execution within a loop, is the <code class="function">break</code>-command.</span></i></p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520136"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 100
  if mod(a,2)=0 continue
  print a
next a
          </pre><p>This example will print all odd numbers between 1 and 100.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520157"></a><h2>See also</h2><p><code class="function"><a href="#ref_for" title="for">for</a></code>, <code class="function"><a href="#ref_do" title="do">do</a></code>, <code class="function"><a href="#ref_repeat" title="repeat">repeat</a></code>, <code class="function"><a href="#ref_while" title="while">while</a></code>, <code class="function"><a href="#ref_break" title="break">break</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_cos"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>cos() — return the cosine of its single argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=cos(angle)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520247"></a><h2>Description</h2><p>The <code class="function">cos</code>-function expects an angle (in radian) and returns its cosine.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520264"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print cos(pi)
          </pre><p>This example will print <code class="computeroutput">-1</code>.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520289"></a><h2>See also</h2><p><code class="function"><a href="#ref_acos" title="acos()">acos</a></code>, <code class="function"><a href="#ref_sin" title="sin()">sin</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_d"></a>D</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_data">data</a></span><span class="refpurpose"> - introduces a list of data-items</span></dt><dt><span class="refentrytitle"><a href="#ref_date">date$</a></span><span class="refpurpose"> - returns a string with various components of the current date</span></dt><dt><span class="refentrytitle"><a href="#ref_dec">dec()</a></span><span class="refpurpose"> - convert a base 2 or base 16 number into decimal form</span></dt><dt><span class="refentrytitle"><a href="#ref_default">default</a></span><span class="refpurpose"> - mark the default-branch within a switch-statement</span></dt><dt><span class="refentrytitle"><a href="#ref_dim">dim</a></span><span class="refpurpose"> - create an array prior to its first use</span></dt><dt><span class="refentrytitle"><a href="#ref_do">do</a></span><span class="refpurpose"> - start a (conditionless) do-loop</span></dt><dt><span class="refentrytitle"><a href="#ref_doc">doc</a></span><span class="refpurpose"> - special comment, which might be retrieved by the program itself</span></dt><dt><span class="refentrytitle"><a href="#ref_docu">docu$</a></span><span class="refpurpose"> - special array, containing the contents of all docu-statement within the program</span></dt><dt><span class="refentrytitle"><a href="#ref_dot">dot</a></span><span class="refpurpose"> - draw a dot in the graphic-window</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_data"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>data — introduces a list of data-items</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
data 9,"world"
…
read b,a$
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520362"></a><h2>Description</h2><p>The <code class="function">data</code>-keyword introduces a list of comma-separated list of strings or numbers, which may be retrieved with the <code class="function"><a href="#ref_read" title="read">read</a></code>-command.</p><p>The <code class="function">data</code>-command itself does nothing; it just stores data. A single <code class="function">data</code>-command may precede an arbitrarily long list of values, in which strings or numbers may be mixed at will.</p><p><span class="application">yabasic</span> internally uses a <code class="systemitem">data-pointer</code> to keep track of the current location within the <code class="function">data</code>-list; this pointer may be reset with the <code class="function"><a href="#ref_restore" title="restore">restore</a></code>-command.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520440"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
do
  restore
  for a=1 to 4
    read num$,num
    print num$,"=",num
  next a
loop
data "eleven",11,"twelve",12,"thirteen",13,"fourteen",14
          </pre><p>This example just prints a series of lines <code class="computeroutput">eleven=11</code> up to <code class="computeroutput">fourteen=14</code> and so on without end.</p><p>The <code class="function">restore</code>-command ensures that the list of <code class="function">data</code>-items is read from the start with every iteration.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520490"></a><h2>See also</h2><p><code class="function"><a href="#ref_read" title="read">read</a></code>, <code class="function"><a href="#ref_restore" title="restore">restore</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_date"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>date$ — returns a string with various components of the current date</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">a$=date$</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520552"></a><h2>Description</h2><p>The <code class="function">date$</code>-function (which <span class="emphasis"><em>must</em></span> be called without parentheses; i.e. <code class="function">date$()</code> would be an error) returns a string containing various components of a date; an example would be <code class="computeroutput">4-05-27-2004-Thu-May</code>. This string consists of various fields separated by hyphens ("<code class="computeroutput">-</code>"):</p><div class="itemizedlist"><ul type="disc"><li><p>The day within the week as a number in the range 0 (=Sunday) to 6 (=Saturday) (in the example above: <code class="computeroutput">4</code>, i.e. thursday).</p></li><li><p>The month as a number in the range 1 (=January) to 12 (=December) (in the example: <code class="computeroutput">5</code> which stands for May).</p></li><li><p>The day within the month as a number in the range 1 to 31 (in the example: <code class="computeroutput">27</code>).</p></li><li><p>The full, 4-digit  year (in the example: <code class="computeroutput">2004</code>, which reminds me that I should adjust the clock within my computer …).</p></li><li><p>The abbreviated name of the day within the week (<code class="computeroutput">Mon</code> to <code class="computeroutput">Sun</code>).</p></li><li><p>The abbreviated name of the month (<code class="computeroutput">Jan</code> to <code class="computeroutput">Dec</code>).</p></li></ul></div><p>Therefore the whole example above (<code class="computeroutput">4-05-27-2004-Thu-May</code>) would read: day 4 in the week (counting from 0), May 27 in the year 2004, which is a Thursday in May.</p><p>Note, that all fields within the string returned by <code class="function">date$</code> have a fixed with (numbers are padded with zeroes); therefore it is easy to extract the various fields of a date format with <code class="function">mid$</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520717"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
rem   Two ways to print the same ...

print mid$(date$,3,10)

dim fields$(6)
a=split(date$,fields$(),"-")
print fields$(2),"-",fields$(3),"-",fields$(4)
          </pre><p>This example shows two different techniques to extract components from the value returned by <code class="function">date$</code>. The <code class="function">mid$</code>-function is the preferred way, but you could just as well <code class="function">split</code> the return-value of <code class="function">date$</code> at every "-" and store the result within an array of strings.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520767"></a><h2>See also</h2><p><code class="function"><a href="#ref_time" title="time$">time$</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_dec"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>dec() — convert a base 2 or base 16 number into decimal form</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a=dec(number$)
a=dec(number$,base)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520819"></a><h2>Description</h2><p>The <code class="function">dec</code>-function takes the string-representation of a base-2 or base-16 (which is the default) number and converts it into a decimal number. The optional second argument (<code class="varname">base</code>) might be used to specify a base other than 16. However, currently only base 2 or base 16 are supported.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520843"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a binary number: " a$
print a$," is ",dec(a$)
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520860"></a><h2>See also</h2><p><a href="#ref_bin" title="bin$()"><code class="function">bin$</code></a>, <a href="#ref_hex" title="hex$()"><code class="function">hex$</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_default"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>default — mark the <span class="emphasis"><em>default</em></span>-branch within a <code class="function"><a href="#ref_switch" title="switch">switch</a></code>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
switch a+3
case 1
  …
case 2
  …
default
  …
end switch
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520936"></a><h2>Description</h2><p>The <code class="function">default</code>-clause is an optional part of the <code class="function"><a href="#ref_switch" title="switch">switch</a></code>-statement (see there for more information). It introduces a series of statements, that should be executed, if none of the cases matches, that have been specified before (each with its own <code class="function"><a href="#ref_case" title="case">case</a></code>-clause).</p><p>So <code class="function">default</code> specifies a default to be executed, if none of the explicitly named cases matches; hence its name.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2520986"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "Please enter a number between 0 and 6,"
print "specifying a day in the week."
input d
switch d
case 0:print "Monday":break
case 1:print "Tuesday":break
case 2:print "Wednesday":break
case 3:print "Thursday":break
case 4:print "Friday":break
case 5:print "Saturday":break
case 6:print "Sunday":break
default:print "Hey you entered something invalid !"
end switch
          </pre><p>This program translates a number between 0 and 6 into the name of a weekday; the <code class="function">default</code>-case is used to detect (and complain about) invalid input.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521020"></a><h2>See also</h2><p><a href="#ref_sub" title="sub"><code class="function">sub</code></a>, <a href="#ref_case" title="case"><code class="function">case</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_dim"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>dim — create an array prior to its first use</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
dim array(x,y)
dim array$(x,y)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521080"></a><h2>Description</h2><p>The <code class="function">dim</code>-command prepares one or more arrays (of either strings or numbers) for later use. This command can also be used to enlarges an existing array.</p><p>When an array is created with the <code class="function">dim</code>-statement, memory is allocated and all elements are initialized with either 0 (for numerical arrays) or "" (for string arrays).</p><p>If the array already existed, and the <code class="function">dim</code>-statement specifies a larger size than the current size, the array is enlarged and any old content is preserved.</p><p>Note, that <code class="function">dim</code> cannot be used to shrink an array: If you specify a size, that is smaller than the current size, the <code class="function">dim</code>-command does nothing.</p><p>Finally: To create an array, that is only known within a single subroutine, you should use the command <code class="function"><a href="#ref_local" title="local">local</a></code>, which creates local variables as well as local arrays.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521153"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
dim a(5,5)
for x=1 to 5:for y=1 to 5
  a(x,y)=int(ran(100))
next y:next x
printmatrix(a())
dim a(7,7)
printmatrix(a())

sub printmatrix(ar())
  local x,y,p,q
  x=arraysize(ar(),1)
  y=arraysize(ar(),2)
  for q=1 to y
    for p=1 to y
      print ar(p,q),"\t";
    next p
    print
  next q
end sub
          </pre><p>This example creates a 2-dimenional array (i.e. a <span class="emphasis"><em>matrix</em></span>) with the <code class="function">dim</code>-statement and fills it with random numbers. The second <code class="function">dim</code>-statement enlarges the array, all new elements are filled with 0.</p><p>The subroutine <code class="function">printmatrix</code> just does, what its name says.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521205"></a><h2>See also</h2><p><a href="#ref_arraysize" title="arraysize()"><code class="function">arraysize</code></a>, <a href="#ref_arraydim" title="arraydim()"><code class="function">arraydim</code></a>, <code class="function"><a href="#ref_local" title="local">local</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_do"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>do — start a (conditionless) <code class="function">do-loop</code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
do 
… 
loop</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521282"></a><h2>Description</h2><p>Starts a loop, which is terminated by <code class="function">loop</code>; everything between <code class="function">do</code> and <code class="function">loop</code> will be repeated forever. This loop has no condition, so it is an infinite loop; note however, that a <code class="function"><a href="#ref_break" title="break">break</a></code>- or <code class="function"><a href="#ref_goto" title="goto">goto</a></code>-statement might be used to leave this loop anytime.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521333"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
do
  a=a+1
  print a
  if (a&gt;100) break
loop
          </pre><p>This example prints the numbers between 1 and 101. The <code class="function">break</code>-statement is used to leave the loop.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521360"></a><h2>See also</h2><p><a href="#ref_loop" title="loop"><code class="function">loop</code></a>, <a href="#ref_repeat" title="repeat"><code class="function">repeat</code></a>, <a href="#ref_while" title="while"><code class="function">while</code></a>, <a href="#ref_break" title="break"><code class="function">break</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_doc"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>doc — special comment, which might be retrieved by the program itself</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
doc   This is a comment
docu  This is another comment
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521442"></a><h2>Description</h2><p>Introduces a comment, which spans up to the end of the line. But other than the <a href="#ref_rem" title="rem"><code class="function">rem</code></a>-comment, any <code class="function">docu</code>-comment is collected within the special <code class="function"><a href="#ref_docu" title="docu$">docu$</a></code>-array and might be retrieved later on. Moreover you might invoke <span class="application">yabasic -docu foo.yab</span> on the <span class="emphasis"><em>commandline</em></span> to retrieve the embedded documentation within the program <code class="literal">foo.yab</code>.</p><p>Instead of <code class="function">doc</code> you may just as well write <code class="function">docu</code> or even <code class="function">documentation</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521518"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
rem   Hi, this has been written by me
rem
doc   This program asks for a number and
doc   prints this number multiplied with 2
rem
rem   Print out rhe above message
for a=1 to arraysize(docu$()):print docu$(a):next a

rem   Read and print the number
input "Please input a number: " x
print x*2
          </pre><p>This program uses the comments within its code to print out a help message for the user.</p><p>The contents of the <code class="function">doc</code>-lines are retrieved from the <code class="function">docu$</code>-array; if you do not want a comment to be collected within this array, use the <code class="function">rem</code>-statement instead.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521567"></a><h2>See also</h2><p><a href="#ref_docu" title="docu$"><code class="function">docu$</code></a>, <a href="#ref_rem" title="rem"><code class="function">rem</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_docu"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>docu$ — special array, containing the contents of all docu-statement within the program</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">a$=docu$(1)</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521628"></a><h2>Description</h2><p>Before your program is executed, <span class="application">yabasic</span> collects the content of all the <code class="function">doc</code>-statements within your program within this 1-dimensional array (well only those within the main-program, libraries are skipped).</p><p>You may use the <code class="function">arraysize</code> function to find out, how many lines it contains.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521663"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
docu
docu  This program reads two numbers 
docu  and adds them.
docu

rem retrieve and print the embedded documentation
for a=1 to arraysize(docu$(),1)
  print docu$(a)
next a

input "First number: " b
input "Second number: " c

print "The sum of ",b," and ",c," is ",b+c
          </pre><p>This program uses the embedded documentation to issue a usage-message.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521688"></a><h2>See also</h2><p><a href="#ref_arraysize" title="arraysize()"><code class="function">arraydim</code></a>, <a href="#ref_rem" title="rem"><code class="function">rem</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_dot"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>dot — draw a dot in the graphic-window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
dot x,y
clear dot x,y
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521749"></a><h2>Description</h2><p>Draws a dot at the specified coordinates within your graphic-window. If <a href="#ref_open_printer" title="open printer">printing</a> is in effect, the dot appears on your printout too.</p><p>Use the functions <a href="#ref_peek" title="peek"><code class="function">peek("winheight")</code></a> or <a href="#ref_peek" title="peek"><code class="function">peek("winwidth")</code></a> to get the size of your window and hence the boundaries of the coordinates specified for the <code class="function">dot</code>-command.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521799"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
circle 100,100,100
do
  x=ran(200):y=ran(200)
  dot x,y
  total=total+1
  if (sqrt((x-100)^2+(y-100)^2)&lt;100) in=in+1
  print 4*in/total
loop
          </pre><p>This program uses a well known algorithm to compute π.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521824"></a><h2>See also</h2><p><a href="#ref_line" title="line"><code class="function">line</code></a>, <a href="#ref_open_window" title="open window"><code class="function">open window</code></a></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_e"></a>E</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_else">else</a></span><span class="refpurpose"> - mark an alternative within an if-statement</span></dt><dt><span class="refentrytitle"><a href="#ref_elsif">elsif</a></span><span class="refpurpose"> - starts an alternate condition within an if-statement</span></dt><dt><span class="refentrytitle"><a href="#ref_end">end</a></span><span class="refpurpose"> - terminate your program</span></dt><dt><span class="refentrytitle"><a href="#ref_endif">endif</a></span><span class="refpurpose"> - ends an if-statement</span></dt><dt><span class="refentrytitle"><a href="#ref_end_sub">end sub</a></span><span class="refpurpose"> - ends a subroutine definition</span></dt><dt><span class="refentrytitle"><a href="#ref_eof">eof</a></span><span class="refpurpose"> - check, if an open file contains data</span></dt><dt><span class="refentrytitle"><a href="#ref_eor">eor()</a></span><span class="refpurpose"> - compute the bitwise exclusive or of its two arguments</span></dt><dt><span class="refentrytitle"><a href="#ref_error">error</a></span><span class="refpurpose"> - raise an error and terminate your program</span></dt><dt><span class="refentrytitle"><a href="#ref_euler">euler</a></span><span class="refpurpose"> - another name for the constant 2.71828182864</span></dt><dt><span class="refentrytitle"><a href="#ref_execute2">execute$()</a></span><span class="refpurpose"> - execute a user defined subroutine, which must return a string</span></dt><dt><span class="refentrytitle"><a href="#ref_execute">execute()</a></span><span class="refpurpose"> - execute a user defined subroutine, which must return a number</span></dt><dt><span class="refentrytitle"><a href="#ref_exit">exit</a></span><span class="refpurpose"> - terminate your program</span></dt><dt><span class="refentrytitle"><a href="#ref_exp">exp()</a></span><span class="refpurpose"> - compute the exponential function of its single argument</span></dt><dt><span class="refentrytitle"><a href="#ref_export">export</a></span><span class="refpurpose"> - mark a function as globally visible</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_else"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>else — mark an alternative within an <code class="function">if</code>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (…) then 
  … 
else 
  … 
endif
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521903"></a><h2>Description</h2><p>The <code class="function">else</code>-statement introduces the alternate branch of an <code class="function">if</code>-statement. I.e. it starts the sequence of statements, which is executed, if the condition of the <code class="function">if</code>-statement is <span class="emphasis"><em>not</em></span> true.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521936"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a number: " a
if (mod(a,2)=1) then
  print a," is odd."
else
  print a," is even."
endif
          </pre><p>This program detects, if the number you have entered is even or odd.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2521958"></a><h2>See also</h2><p><a href="#ref_if" title="if"><code class="function">if</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_elsif"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>elsif — starts an alternate condition within an <code class="function">if</code>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (…) then
  …
elseif (…) 
  …
elsif (…) then
  …
else
  …
endif
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522016"></a><h2>Description</h2><p>The <code class="function">elsif</code>-statement is used to select a single alternative among a series of choices.</p><p>With each <code class="function">elsif</code>-statement you may specify a condition, which is tested, if the main condition (specified with the <code class="function">if</code>-statement) has failed. Note that <code class="function">elsif</code> might be just as well written as <code class="function">elseif</code>.</p><p>Within the example below, two variables <code class="function">a</code> and <code class="function">b</code> are tested against a range of values. The variable <code class="function">a</code> is tested with the <code class="function">elsif</code>-statement. The very same tests are performed for the variable <code class="function">b</code> too; but here an involved series of <code class="function">if</code>-<code class="function">else</code>-statements is employed, making the tests much more obscure.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522110"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a number: " a
if (a&lt;0) then
  print "less than 0"
elseif (a&lt;=10) then
  print "between 0 and 10"
elsif (a&lt;=20)
  print "between 11 and 20"
else
  print "over 20"
endif

input "Please enter another number: " b
if (b&lt;0) then
  print "less than 0"
else
  if (b&lt;=10) then
    print "between 0 and 10"
  else
    if (b&lt;=20) then
      print "between 11 and 20"
    else
      print "over 20"
    endif
  endif
endif
          </pre><p>Note, that the very same tests are performed for the variables <code class="function">a</code> and <code class="function">b</code>, but can be stated much more clearly with the <code class="function">elsif</code>-statement.</p><p>Note, that <code class="function">elsif</code> might be written as <code class="function">elseif</code> too, and that the keyword <code class="function">then</code> is optional.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522180"></a><h2>See also</h2><p><a href="#ref_if" title="if"><code class="function">if</code></a>, <a href="#ref_else" title="else"><code class="function">else</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_end"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>end — terminate your program</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
end
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522239"></a><h2>Description</h2><p>Terminate your program. Much (but not exactly) like the <code class="function"><a href="#ref_exit" title="exit">exit</a></code> command.</p><p>Note, that <code class="function">end</code> may not end your program immediately; if you have opened a window or called <code class="function">clear screen</code>, <span class="application">yabasic</span> assumes, that your user wants to study the output of your program after it has ended; therefore it issues the line <code class="computeroutput">---Program done, press RETURN---</code> and waits for a key to be pressed. If you do not like this behaviour, consider using <code class="function"><a href="#ref_exit" title="exit">exit</a></code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522302"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "Do you want to continue ?"
input "Please answer y(es) or n(o): " a$
if (lower$(left$(a$,1))="n") then
  print "bye"
  end
fi
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522320"></a><h2>See also</h2><p><code class="function"><a href="#ref_exit" title="exit">exit</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_endif"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>endif — ends an <code class="function">if</code>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (…) then
  …
endif
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522377"></a><h2>Description</h2><p>The <code class="function">endif</code>-statement closes (or ends) an <code class="function">if</code>-statement.</p><p>Note, that <code class="function">endif</code> may be written in a variety of other ways: <code class="function">end if</code>, <code class="function">end-if</code> or even <code class="function">fi</code>.</p><p>The <code class="function">endif</code>-statement must be omitted, if the <code class="function">if</code>-statement does not contain the keyword <code class="function">then</code> (see the example below). Such an <a href="#ref_if" title="if"><code class="function">if</code></a>-statement without <code class="function">endif</code> extends only over a single line.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522465"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "A number please: " a
if (a&lt;10) then
  print "Your number is less than 10."
endif

REM  and now without endif 

input "A number please: " a
if (a&lt;10) print "Your number is less than 10."
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522487"></a><h2>See also</h2><p><a href="#ref_if" title="if"><code class="function">if</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_end_sub"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>end sub — ends a subroutine definition</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
sub foo(…) 
  …
end sub
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522538"></a><h2>Description</h2><p>Marks the end of a subroutine-definition (which starts with the <code class="function">sub</code>-keyword).
	  The whole concept of subroutines is explained within the entry for <a href="#ref_sub" title="sub"><code class="function">sub</code></a>.
</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522566"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print foo(3)

sub foo(a)
  return a*2
end sub
          </pre><p>This program prints out <code class="computeroutput">6</code>. The subroutine <code class="function">foo</code> simply returns twice its argument.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522598"></a><h2>See also</h2><p><a href="#ref_sub" title="sub"><code class="function">sub</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_eof"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>eof — check, if an open file contains data</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open 1,"foo.bar"
if (eof(1)) then 
   …
end if
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522650"></a><h2>Description</h2><p>The <code class="function">eof</code>-function checks, if there is still data left within an open file. As an argument it expects the file-number as returned by (or used within) the <code class="function">open</code>-function (or statement).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522674"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
a=open("foo.bar")
while(not eof(a)) 
  input #a,a$
  print a$
end while
          </pre><p>This example will print the contents of the file "foo.bar". The <code class="function">eof</code>-function will terminate the loop, if there is no more data left within the file. </p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522702"></a><h2>See also</h2><p><a href="#ref_open" title="open"><code class="function">open</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_eor"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>eor() — compute the bitwise <span class="emphasis"><em>exclusive or</em></span> of its two arguments</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">print eor(a,b)</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522758"></a><h2>Description</h2><p>The <code class="function">eor</code>-function takes two arguments and computes their bitwise <span class="emphasis"><em>exclusive or</em></span>. See your favorite introductory text on informatics for an explanation of this function.</p><p>The <code class="function">xor</code>-function is the same as the <code class="function">eor</code> function; both are synonymous; however they have each their own description, so you may check out the entry of <code class="function"><a href="#ref_xor" title="xor()">xor</a></code> for a slightly different view.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522808"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=0 to 3
  for b=0 to 3
    print fill$(bin$(a))," eor ",fill$(bin$(b))," = ",fill$(bin$(eor(a,b)))
  next b
next a

sub fill$(a$)
  return right$("0"+a$,2)
end sub
          </pre><p>This example prints a table, from which you may figure, how the <code class="function">eor</code>-function is computed.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522836"></a><h2>See also</h2><p><a href="#ref_arithmetic_and" title="and()"><code class="function">and</code></a>, <a href="#ref_arithmetic_or" title="or()"><code class="function">or</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_error"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>error — raise an error and terminate your program</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">error "Wrong, wrong, wrong !!"</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522897"></a><h2>Description</h2><p>Produces the same kind or error messages, that yabasic itself produces (e.g. in case of a syntax-error). The single argument is issued along with the current line-number.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522909"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a number between 1 and 10: " a
if (a&lt;1 or a&gt;10) error "Oh no ..."
          </pre><p>This program is very harsh in checking the users input; instead of just asking again, the program terminates with an error, if the user enters something wrong.</p><p>The error message would look like this:</p><pre class="programlisting">
---Error in t.yab, line 2: Oh no ...
---Error: Program stopped due to an error
</pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2522944"></a><h2>See also</h2><p>Well, there <span class="emphasis"><em>should</em></span> be a corresponding called <code class="function">warning</code>; unfortunately ther is none yet.</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_euler"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>euler — another name for the constant <code class="function">2.71828182864</code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">foo=euler</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523003"></a><h2>Description</h2><p><code class="function">euler</code> is the well known constant named after <span class="emphasis"><em>Leonard Euler</em></span>; its value is <code class="function">2.71828182864</code>. <code class="function">euler</code> is <span class="emphasis"><em>not</em></span> a function, so parens are not allowed (i.e. <code class="function">euler()</code> will produce an error). Finally, you may not assign to <code class="function">euler</code>; it wouldn't sense anyway, because it is a constant.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523052"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print euler
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523068"></a><h2>See also</h2><p><code class="function"><a href="#ref_pi" title="pi">pi</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_execute2"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>execute$() — execute a user defined subroutine, which must return a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">print execute$("foo$","arg1","arg2")</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523120"></a><h2>Description</h2><p><code class="function">execute$</code> can be used to execute a user defined subroutine, whose name may be specified as a string expression.</p><p>This feature is the only way to execute a subroutine, whose name is not known by the time you write your program. This might happen, if you want to execute a subroutine, which is compiled (using the <code class="function"><a href="#ref_compile" title="compile">compile</a></code> command) during the course of execution of your program.</p><p>Note however, that the <code class="function">execute$</code>-function is <span class="emphasis"><em>not</em></span> the preferred method to execute a user defined subroutine; almost all cases you should just execute a subroutine by writing down its name within your yabasic program (see the example).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523170"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print execute$("foo$","Hello","world !")
sub foo$(a$,b$)
  return a$+" "+b$
end sub
          </pre><p>The example simply prints <code class="computeroutput">Hello world !</code>, which is the return value of the user defined subroutine <code class="function">foo$</code>. The same could be achieved by executing:</p><pre class="programlisting">
print foo$(a$,b$)
</pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523210"></a><h2>See also</h2><p><code class="function"><a href="#ref_compile" title="compile">compile</a></code>, <code class="function"><a href="#ref_execute" title="execute()">execute</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_execute"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>execute() — execute a user defined subroutine, which must return a number</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">print execute("bar","arg1","arg2")</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523272"></a><h2>Description</h2><p>The <code class="function">execute</code>-function is the counterpart of the <code class="function"><a href="#ref_execute2" title="execute$()">execute$</a></code>-function (please see there for some caveats). <code class="function">execute</code> executes subroutines, which returns a number.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523308"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print execute("bar",2,3)
sub bar(a,b)
  return a+b
end sub
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523324"></a><h2>See also</h2><p><code class="function"><a href="#ref_compile" title="compile">compile</a></code>, <code class="function"><a href="#ref_execute2" title="execute$()">execute$</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_exit"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>exit — terminate your program</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
exit
exit 1
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523385"></a><h2>Description</h2><p>Terminate your program and return any given value to the operating system. <code class="function">exit</code> is similar to <code class="function"><a href="#ref_end" title="end">end</a></code>, but it will terminate your program immediately, no matter what.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523413"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "Do you want to continue ?"
input "Please answer y(es) or n(o): " a$
if (lower$(left$(a$,1))="n") exit 1
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523431"></a><h2>See also</h2><p><code class="function"><a href="#ref_end" title="end">end</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_exp"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>exp() — compute the exponential function of its single argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
foo=exp(bar)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523482"></a><h2>Description</h2><p>This function computes <span class="emphasis"><em>e</em></span> to the power of its argument, where <span class="emphasis"><em>e</em></span> is the well known euler constant <code class="function">2.71828182864</code>.</p><p>The <code class="function">exp</code>-function is the inverse of the <code class="function">log</code>-function.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523521"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 100,100
for x=0 to 100
   dot x,100-100*exp(x/100)/euler
next x
          </pre><p>This program plots part of the <code class="function">exp</code>-function, however the range is rather small, so that you may not recognize the function from this plot.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523549"></a><h2>See also</h2><p><code class="function"><a href="#ref_log" title="log()">log</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_export"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>export — mark a function as globally visible</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
export sub foo(bar)
…
end sub
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523601"></a><h2>Description</h2><p>The <code class="function">export</code>-statement is used within libraries to mark a user defined subroutine as visible outside the library wherein it is defined. Subroutines, which are not exported, must be qualified with the name of the library, e.g. <code class="function">foo.baz</code> (where <code class="function">foo</code> is the name of the library and <code class="function">baz</code> the name of the subroutine); <span class="emphasis"><em>exported</em></span> subroutines may be used without specifying the name of the library, e.g. <code class="function">bar</code>.</p><p>Therefore <code class="function">export</code> may only be useful within libraries.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523659"></a><h2>Example</h2><div class="informalexample"><p>The library <code class="filename">foo.bar</code> (which is listed below) defines two functions <code class="function">bar</code> and <code class="function">baz</code>, however only the function <code class="function">bar</code> is <span class="emphasis"><em>exported</em></span> and therefore visible even outside the library; <code class="function">baz</code> is <span class="emphasis"><em>not</em></span> exported and may only be used within the library <code class="computeroutput">foo.yab</code>:</p><pre class="programlisting">
export sub bar()
  print "Hello"
end sub

sub baz()
  print "World"
end sub
          </pre><p>Now within your main program <code class="filename">cux.yab</code> (which <code class="function"><a href="#ref_import" title="import">import</a></code>s the library foo.yab); note that this program produces an error:</p><pre class="programlisting">
import foo

print "Calling subroutine foo.bar (okay) ..."
foo.bar()
print "done."

print "Calling subroutine bar (okay) ..."
bar()
print "done."

print "Calling subroutine foo.baz (okay) ..."
foo.baz()
print "done."

print "Calling subroutine baz (NOT okay) ..."
baz()
print "done."

</pre><p>The output when executing <span><strong class="command">yabasic foo.yab</strong></span> is this:</p><pre class="programlisting">
Calling subroutine foo.bar (okay) ...
Hello
done.
Calling subroutine bar (okay) ...
Hello
done.
Calling subroutine foo.baz (okay) ...
World
done.
Calling subroutine baz (NOT okay) ...
---Error in main.yab, line 16: can't find subroutine 'baz'
---Dump: sub baz() called in main.yab,16
---Error: Program stopped due to an error
</pre><p>As the error message above shows, the subroutine <code class="function">baz</code> must be qualified with the name of the library, if used outside the library, wherein it is defined (e.g. <code class="function">foo.baz</code>. I.e. outside the library <code class="filename">foo.yab</code> you need to write <code class="filename">foo.baz</code>. <code class="function">baz</code> alone would be an error.</p><p>The subroutine <code class="function">bar</code> (without adding the name of the library) however may (and probably should) be used in any program, which imports the library <code class="filename">foo.yab</code>.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>In some sense the set of exported subroutines constitutes the <span class="emphasis"><em>interface</em></span> of a library.</p></div></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523840"></a><h2>See also</h2><p><code class="function"><a href="#ref_sub" title="sub">sub</a></code>, <code class="function"><a href="#ref_import" title="import">import</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_f"></a>F</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_false">false</a></span><span class="refpurpose"> - a constant with the value of 0</span></dt><dt><span class="refentrytitle"><a href="#ref_fi">fi</a></span><span class="refpurpose"> - another name for endif</span></dt><dt><span class="refentrytitle"><a href="#ref_fill">fill</a></span><span class="refpurpose"> - draw a filled circles, rectangles or triangles</span></dt><dt><span class="refentrytitle"><a href="#ref_for">for</a></span><span class="refpurpose"> - starts a for-loop</span></dt><dt><span class="refentrytitle"><a href="#ref_frac">frac()</a></span><span class="refpurpose"> - return the fractional part of its numeric argument</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_false"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>false — a constant with the value of 0</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
okay=false
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523913"></a><h2>Description</h2><p>The constant <code class="function">false</code> can be assigned to variables which later appear in conditions (e.g. within an <code class="function">if</code>-statement.</p><p><code class="function">false</code> may also be written as <code class="function">FALSE</code> or even <code class="function">FaLsE</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523956"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a number between 1 and 10: " a
if (check_input(a)) print "Okay"

sub check_input(x)
  if (x&gt;10 or x&lt;1) return false
  return true
end sub
          </pre><p>The subroutine <code class="function">check_input</code> checks its argument and returns <code class="function">true</code> or <code class="function">false</code> according to the outcome of the check..</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2523998"></a><h2>See also</h2><p><code class="function"><a href="#ref_true" title="true">true</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_fi"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>fi — another name for <code class="function"><a href="#ref_endif" title="endif">endif</a></code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (…)
…
fi
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524057"></a><h2>Description</h2><p><code class="function">fi</code> marks the end of an <code class="function">if</code>-statement and is exactly equivalent to <code class="function"><a href="#ref_endif" title="endif">endif</a></code>, please see there for further information.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524089"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "A number please: " a
if (a&lt;10) then
  print "Your number is less than 10."
fi
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524109"></a><h2>See also</h2><p><code class="function"><a href="#ref_endif" title="endif">endif</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_fill"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>fill — draw a filled <code class="function">circle</code>s, <code class="function">rectangle</code>s or <code class="function">triangle</code>s</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
fill rectangle 10,10,90,90
fill circle 50,50,20
fill triangle 10,20,20,10,20,20
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524178"></a><h2>Description</h2><p>The keyword <code class="function">fill</code> may be used within the <code class="function"><a href="#ref_circle" title="circle">circle</a></code>, <code class="function"><a href="#ref_rectangle" title="rectangle">rectangle</a></code> or <code class="function"><a href="#ref_triangle" title="triangle">triangle</a></code> command and causes these shapes to be filled.</p><p><code class="function">fill</code> can be used in conjunction with and wherever the <code class="function"><a href="#ref_clear" title="clear">clear</a></code>-clause may appear. Used alone, <code class="function">fill</code> will fill the interior of the shape (circle, rectangle or triangle); together with <code class="function">clear</code> the whole shape (including its interior) is erased.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524259"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
fill circle 100,100,50
clear fill rectangle 10,10,90,90
          </pre><p>This opens a window and draws a pacman-like figure.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524281"></a><h2>See also</h2><p><code class="function"><a href="#ref_clear" title="clear">clear</a></code>, <code class="function"><a href="#ref_circle" title="circle">circle</a></code>, <code class="function"><a href="#ref_rectangle" title="rectangle">rectangle</a></code>, <code class="function"><a href="#ref_triangle" title="triangle">triangle</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_for"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>for — starts a <code class="function">for</code>-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
for a=1 to 100 step 2
  …
next a
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524368"></a><h2>Description</h2><p>The <code class="function">for</code>-loop lets its numerical variable (<code class="function">a</code> in the synopsis) assume all values within the given range. The optional <code class="function">step</code>-clause may specify a value (default: 1) by which the variable will be incremented (or decremented, if <code class="function">step</code> is negative).</p><p>Any <code class="function">for</code>-statement can be replaced by a set of <code class="function">if</code>s and <code class="function">goto</code>s; as you may infer from the example below this is normally not feasible. However if you want to know in detail how the <code class="function">for</code>-statement works, you should study this example, which presents a <code class="function">for</code>-statement and an <span class="emphasis"><em>exactly equivalant</em></span> series of <code class="function">if</code>s and <code class="function">goto</code>s.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524456"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 10 step 2:print a:next 

a=1
label check
if (a&gt;10) goto done
  print a
  a=a+2
goto check
label done
          </pre><p>This example simply prints the numbers 1, 3, 5, 7 and 9. It does this twice: First with a simple <code class="function">for</code>-statement and then with <code class="function">if</code>s and <code class="function">goto</code>s.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524495"></a><h2>See also</h2><p><code class="function"><a href="#ref_step" title="step">step</a></code>, <code class="function"><a href="#ref_next" title="next">next</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_frac"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>frac() — return the fractional part of its numeric argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=frac(y)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524556"></a><h2>Description</h2><p>The <code class="function">frac</code>-function takes its argument, removes all the digits to the left of the comma and just returns the digits right of the comma, i.e. the fractional part.</p><p>Refer to the example to learn how to rewrite <code class="function">frac</code> by employing the <code class="function">int</code>-function.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524591"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 10
  print frac(sqr(a))
  print sqr(a)-int(sqr(a))
next a
          </pre><p>The example prints the fractional part of the square root of the numbers between 1 and 10. Each result is computed (and printed) twice: Once by employing the <code class="function">frac</code>-function and once by employing the <code class="function"><a href="#ref_int" title="int()">int</a></code>-function.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524630"></a><h2>See also</h2><p><code class="function"><a href="#ref_int" title="int()">int</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_g"></a>G</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_getbit">getbit$()</a></span><span class="refpurpose"> - return a string representing the bit pattern of a rectangle within the graphic window</span></dt><dt><span class="refentrytitle"><a href="#ref_getscreen">getscreen$()</a></span><span class="refpurpose"> - returns a string representing a rectangular section of the text terminal</span></dt><dt><span class="refentrytitle"><a href="#ref_glob">glob()</a></span><span class="refpurpose"> - check if a string matches a simple pattern</span></dt><dt><span class="refentrytitle"><a href="#ref_gosub">gosub</a></span><span class="refpurpose"> - continue execution at another point within your program (and return later)</span></dt><dt><span class="refentrytitle"><a href="#ref_goto">goto</a></span><span class="refpurpose"> - continue execution at another point within your program (and never come back)</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_getbit"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>getbit$() — return a string representing the bit pattern of a rectangle within the graphic window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a$=getbit$(10,10,20,20)
a$=getbit$(10,10 to 20,20)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524694"></a><h2>Description</h2><p>The function <code class="function">getbit</code> returns a string, which contains the encoded bit-pattern of a rectangle within graphic window; the four arguments represent the borders of the rectangle. The string returned might later be fed to the <code class="function"><a href="#ref_putbit" title="putbit">putbit</a></code>-command. </p><p>The <code class="function">getbit$</code>-function might be used for simple animations (as in the example below).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524734"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 40,40
fill circle 20,20,18
circle$=getbit$(0,0,40,40)
close window

open window 200,200
for x=1 to 200
  putbit circle$,x,80
next x
          </pre><p>This example features a circle moving from left to right over the window.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524757"></a><h2>See also</h2><p><code class="function"><a href="#ref_putbit" title="putbit">putbit</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_getscreen"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>getscreen$() — returns a string representing a rectangular section of the text terminal</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a$=getscreen$(2,2,20,20)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524809"></a><h2>Description</h2><p>The <code class="function">getscreen$</code> function returns a string representing the area of the screen as specified by its four arguments (which specify two corners). I.e. everything you have printed within this rectangle will be encoded in the string returned (including any colour-information).</p><p>Like most other commands dealing with advanced text output, <code class="function">getscreen$</code> requires, that you have called <code class="function">clear screen</code> before.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524846"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen

for a=1 to 1000:
	print color("red") "1";
	print color("green") "2";
	print color("blue") "3";
next a  
screen$=getscreen$(10,10,40,10)
print at(10,10) " Please Press 'y' or 'n' ! "
a$=inkey$
putscreen screen$,10,10
          </pre><p>This program fills the screen with colored digits and afterwards asks the user for a choice (<code class="computeroutput"> Please press 'y' or 'n' ! </code>). Afterwards the area of the screen, which has been overwritten by the question will be restored with its previous contents, whhch had been saved via <code class="function">getscreen$</code>.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524885"></a><h2>See also</h2><p><code class="function">putscreen$</code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_glob"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>glob() — check if a string matches a simple pattern</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (glob(string$,pattern$)) …
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524932"></a><h2>Description</h2><p>The <code class="function">glob</code>-function takes two arguments, a string and a (glob-) pattern, and checks if the string matches the pattern. However <code class="function">glob</code> does <span class="emphasis"><em>not</em></span> employ the powerful rules of regular expressions; rather it has only two <span class="emphasis"><em>special</em></span> characters: <code class="computeroutput">*</code> (which matches any number (even zero) of characters) and <code class="computeroutput">?</code> (which matches exactly a single character).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2524978"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 10
  read string$,pattern$
  if (glob(string$,pattern$)) then
    print string$," matches ",pattern$
  else
    print string$," does not match ",pattern$
  endif
next a

data "abc","a*"
data "abc","a?"
data "abc","a??"
data "abc","*b*"
data "abc","*"
data "abc","???"
data "abc","?"
data "abc","*c"
data "abc","A*"
data "abc","????"
          </pre><p>This program checks the string <code class="computeroutput">abc</code> against various patterns and prints the result. The output is:</p><pre class="screen">
abc matches a*
abc does not match a?
abc matches a??
abc matches *b*
abc matches *
abc matches ???
abc does not match ?
abc matches *c
abc does not match A*
abc does not match ????
</pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525019"></a><h2>See also</h2><p>There are no related commands.</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_gosub"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>gosub — continue execution at another point within your program (and return later)</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
gosub foo

…

label foo
…
return
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525064"></a><h2>Description</h2><p><code class="function">gosub</code> remembers the current position within your program and then passes the flow of execution to another point (which is normally marked with a <code class="function"><a href="#ref_label" title="label">label</a></code>). Later, when a <code class="function">return</code>-statement is encountered, the execution is resumed at the previous location.</p><p><code class="function">gosub</code> is the traditional command for calling code, which needs to be executed from various places within your program. However, with <span class="emphasis"><em>subroutines</em></span> yabasic offers a much more flexible way to achieve this (and more). Therefore <code class="function">gosub</code> must to be considered obsolete.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525119"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "Do you want to exit ? "
gosub ask
if (r$="y") exit

label ask
input "Please answer yes or no, by typing 'y' or 'n': ",r$
return
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525137"></a><h2>See also</h2><p><code class="function"><a href="#ref_return" title="return">return</a></code>, <code class="function"><a href="#ref_goto" title="goto">goto</a></code>, <code class="function"><a href="#ref_sub" title="sub">sub</a></code>, <code class="function"><a href="#ref_label" title="label">label</a></code>, <code class="function"><a href="#ref_on_gosub" title="on gosub">on gosub</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_goto"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>goto — continue execution at another point within your program (and never come back)</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
goto foo

…

label foo
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525230"></a><h2>Description</h2><p>The <code class="function">goto</code>-statement passes the flow of execution to another point within your program (which is normally marked with a <code class="function"><a href="#ref_label" title="label">label</a></code>).</p><p><code class="function">goto</code> is normally considered obsolete and harmful, however in yabasic it may be put to the good use of leaving loops (e.g. <code class="function">while</code> or <code class="function">for</code>) prematurely. Note however, that subroutines may <span class="emphasis"><em>not</em></span> be left with the <code class="function">goto</code>-statement.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525289"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "Please press any key to continue."
print "(program will continue by itself within 10 seconds)"
for a=1 to 10
  if (inkey$(1)&lt;&gt;"") then goto done
next a
label done
print "Hello World !"
          </pre><p>Here the <code class="function">goto</code>-statement is used to leave the <code class="function">for</code>-loop prematurely.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525325"></a><h2>See also</h2><p><code class="function"><a href="#ref_gosub" title="gosub">gosub</a></code>, <code class="function"><a href="#ref_on_goto" title="on goto">on goto</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_h"></a>H</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_hex">hex$()</a></span><span class="refpurpose"> - convert a number into hexadecimal</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_hex"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>hex$() — convert a number into hexadecimal</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print hex$(foo)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525397"></a><h2>Description</h2><p>The <code class="function">hex$</code>-function converts a number into a string with its hexadecimal representation. <code class="function">hex$</code> is the inverse of the <code class="function">dec</code>-function.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525427"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open 1,"foo"
while(!eof(1))
  print right$("0"+hex$(peek(1)),2)," ";
  i=i+1
  if (mod(i,10)=0) print
end while
print
          </pre><p>This program reads the file <code class="computeroutput">foo</code> and prints its output as a <span class="emphasis"><em>hex</em></span>-dump using the <code class="function">hex</code>-function.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525464"></a><h2>See also</h2><p><code class="function"><a href="#ref_dec" title="dec()">dec</a></code><code class="function"><a href="#ref_bin" title="bin$()">bin</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_i"></a>I</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_if">if</a></span><span class="refpurpose"> - evaluate a condition and execute statements or not, depending on the result</span></dt><dt><span class="refentrytitle"><a href="#ref_import">import</a></span><span class="refpurpose"> - import a library</span></dt><dt><span class="refentrytitle"><a href="#ref_inkey">inkey$</a></span><span class="refpurpose"> - wait, until a key is pressed</span></dt><dt><span class="refentrytitle"><a href="#ref_input">input</a></span><span class="refpurpose"> - read input from the user (or from a file) and assign it to a variable</span></dt><dt><span class="refentrytitle"><a href="#ref_instr">instr()</a></span><span class="refpurpose"> - searches its second argument within the first; returns its position if found</span></dt><dt><span class="refentrytitle"><a href="#ref_int">int()</a></span><span class="refpurpose"> - return the integer part of its single numeric argument</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_if"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>if — evaluate a condition and execute statements or not, depending on the result</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (…) then
  …
endif

if (…) …

if (…) then
  …
else
  …
endif

if (…) then
  …
elsif (…)
  …
elsif (…) then
  …
else
  …
endif
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525538"></a><h2>Description</h2><p>The <code class="function">if</code>-statement is used to evaluate a conditions and take actions accordingly. (As an aside, please note that there is no real difference between <a href="#ref_conditions_and_expressions" title="Conditions and expressions">conditions and expressions</a>.)</p><p>There are two major forms of the <code class="function">if</code>-statement:</p><div class="itemizedlist"><ul type="disc"><li><p>The <span class="emphasis"><em>one-line</em></span>-form <span class="emphasis"><em>without</em></span> the keyword <code class="function">then</code>: </p><pre class="programlisting">if (…) …</pre><p> This form evaluates the condition and if the result is <code class="constant">true</code> executes all commands (separated by colons) upt to the end of the line. There is neither an <code class="function">endif</code> keyword nor an <code class="function">else</code>-branch.</p></li><li><p>The <span class="emphasis"><em>multi-line</em></span>-form <span class="emphasis"><em>with</em></span> the keyword <code class="function">then</code>: </p><pre class="programlisting">if (…) then … elsif (…) … else … endif</pre><p> (where <code class="function">elsif</code> and <code class="function">else</code> are optional, whereas <code class="function">endif</code> is not.</p><p>According to the requirements of your program, you may specify:</p><div class="itemizedlist"><ul type="circle"><li><p><code class="function">elsif(…)</code>, which specifies a condition, that will be evaluated only if the condition(s) whithin <code class="function">if</code> or any preceding <code class="function">elsif</code> did not match.</p></li><li><p><code class="function">else</code>, which introduces a sequence of commands, that will be executed, if none of the conditions above did match. </p></li><li><p><code class="function">endif</code> is required and ends the <code class="function">if</code>-statement.</p></li></ul></div></li></ul></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525734"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a number between 1 and 4: " a
if (a&lt;=1 or a&gt;=4) error "Wrong, wrong !"
if (a=1) then
  print "one"
elsif (a=2)
  print "two"
elsif (a=3)
  print "three"
else
  print "four"
endif
          </pre><p>The input-number between 1 and 4 is simply echoed as text (<code class="computeroutput">one</code>, <code class="computeroutput">two</code>, …). The example demonstrates both forms (<span class="emphasis"><em>short</em></span> and <span class="emphasis"><em>long</em></span>) of the <code class="function">if</code>-statement (Note however, that the same thing can be done, probably somewhat more elegant, with the <code class="function">switch</code>-statement).</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525793"></a><h2>See also</h2><p><code class="function"><a href="#ref_else" title="else">else</a></code>, <code class="function"><a href="#ref_elsif" title="elsif">elsif</a></code>, <code class="function"><a href="#ref_endif" title="endif">endif</a></code>, <code class="function"><a href="#ref_conditions_and_expressions" title="Conditions and expressions">conditions and expressions</a></code>.</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_import"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>import — import a library</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
import foo
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525877"></a><h2>Description</h2><p>The <code class="function">import</code>-statement imports a library. It expects a single argument, which must be the name of a library (without the trailing <code class="computeroutput">.yab</code>). This library will then be read and parsed and its subroutines (and variables) will be made available within the main program.</p><p>Libraries will first be searched within the current directory (i.e. the directory within which you have invoked <span class="application">yabasic</span>), then within a special directory, whose exact location depends on your system. Typical values would be <code class="filename">/usr/lib</code> under Unix or <code class="filename">C:\yabasic\lib</code> under Windows. However only <strong class="userinput"><code>yabasic -help-usage</code></strong> may tell the truth. The location of this second directory may be changed with the option <code class="literal">-library</code> (either under <a href="#windows_options">Windows</a> or <a href="#unix_options">Unix</a>).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2525956"></a><h2>Example</h2><div class="informalexample"><p>Lets say you have a <span class="application">yabasic</span>-program <code class="computeroutput">foo.yab</code>, which imports a library <code class="computeroutput">lib.yab</code>. <code class="computeroutput">foo.yab</code> reads:</p><pre class="programlisting">
import lib

rem  This works ...
lib.x(0)

rem  This works too ..
x(1)

rem  And this.
lib.y(2)

rem  But this not !
y(3)
          </pre><p>Now the library <code class="computeroutput">lib.yab</code> reads:</p><pre class="programlisting">
rem  Make the subroutine x easily available outside this library
export sub x(a)
  print a
  return
end sub

rem  sub y must be referenced by its full name
rem  outside this library
sub y(a)
  print a
  return
end sub
</pre><p>This program produces an error:</p><p>
</p><pre class="programlisting">
0
1
2
---Error in foo.yab, line 13: can't find subroutine 'y'
---Dump: sub y() called in foo.yab,13
---Error: Program stopped due to an error
</pre><p>
As you may see from the error message, <span class="application">yabasic</span> is unable to find the subroutine <code class="function">y</code> without specifying the name of the library (i.e. <code class="function">lib.y</code>). The reason for this is, that <code class="function">y</code>, other than <code class="function">x</code>, is <span class="emphasis"><em>not</em></span> exported from the library <code class="filename">lib.yab</code> (using the <code class="function">export</code>-statement).
</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2526082"></a><h2>See also</h2><p><code class="function"><a href="#ref_export" title="export">export</a></code>, <code class="function"><a href="#ref_sub" title="sub">sub</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_inkey"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>inkey$ — wait, until a key is pressed</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
foo$=inkey$
inkey$
foo$=inkey$(bar)
inkey$(bar)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2526144"></a><h2>Description</h2><p>The <code class="function">inkeys$</code>-function waits, until the user presses a key on the keyboard or a button of his mouse, and returns this very key. An optional argument specifies the number of seconds to wait; if omitted, <code class="function">inkey$</code> will wait indefinitely.</p><p><code class="function">inkey$</code> may only be used, if <code class="function"><a href="#ref_clear_screen" title="clear screen">clear screen</a></code> has been called at least once.</p><p>For normal keys, <span class="application">yabasic</span> simply returns the key, e.g. <code class="computeroutput">a</code>, <code class="computeroutput">1</code> or <code class="computeroutput">!</code>. For function keys you will get <code class="computeroutput">f1</code>, <code class="computeroutput">f2</code> and so on. Other special keys will return these strings respectively: <code class="computeroutput">enter</code>, <code class="computeroutput">backspace</code>, <code class="computeroutput">del</code>, <code class="computeroutput">esc</code>, <code class="computeroutput">scrnup</code> (for <span class="emphasis"><em>screen up</em></span>), <code class="computeroutput">scrndown</code> and <code class="computeroutput">tab</code>. Modifier keys (e.g. <code class="computeroutput">ctrl</code>, <code class="computeroutput">alt</code> or <code class="computeroutput">shift</code>) by themselves can <span class="emphasis"><em>not</em></span> be detected (however, if you press <code class="computeroutput">shift</code> and e.g. <code class="computeroutput">a</code> simultaniously, <code class="function">inkey$</code> will return the letter <code class="computeroutput">A</code> instead of <code class="computeroutput">a</code> of course).</p><p>If a graphical window has been opened (via <code class="function">open window</code>) any mouseclick within this window will be returned by <code class="function">inkey$</code> too. The string returned (e.g. <code class="computeroutput">MB1d+0:0028,0061</code>, <code class="computeroutput">MB2u+0:0028,0061</code> or <code class="computeroutput">MB1d+1:0028,0061</code>) is constructed as follows: </p><div class="itemizedlist"><ul type="disc"><li><p>Every string associated with a mouseclick will start with the fixed string <code class="computeroutput">MB</code></p></li><li><p>The next digit (<code class="computeroutput">1</code>, <code class="computeroutput">2</code> or <code class="computeroutput">3</code>) specifies the mousebutton pressed.</p></li><li><p>A single letter, <code class="computeroutput">d</code> or <code class="computeroutput">u</code>, specifies, if the mousebutton has been pressed or released: <code class="computeroutput">d</code> stands for <span class="emphasis"><em>down</em></span>, i.e. the mousebutton has been pressed; <code class="computeroutput">u</code> means <span class="emphasis"><em>up</em></span>, i.e. the mousebutton has been released.</p></li><li><p>The plus-sign ('<code class="computeroutput">+</code>'), which follows is always fixed.</p></li><li><p>The next digit (in the range 0 to 7) encodes the modifier keys pressed, where <code class="computeroutput">1</code> stands for <code class="computeroutput">shift</code>, <code class="computeroutput">2</code> stands for <code class="computeroutput">alt</code> and <code class="computeroutput">4</code> stands for <code class="computeroutput">ctrl</code>.</p></li><li><p>The next four digits (e.g. <code class="computeroutput">0028</code>) contain the x-position, where the mousebutton has been pressed.</p></li><li><p>The comma to follow is always fixed.</p></li><li><p>The last four digits (e.g. <code class="computeroutput">0061</code>) contain the y-position, where the mousebutton has been pressed.</p></li></ul></div><p>All those fields are of fixed length, so you may use functions like <code class="function">mid$</code> to extract certain fields. However, note that with <code class="function">mousex</code>, <code class="function">mousey</code>, <code class="function">mouseb</code> and <code class="function">mousemod</code> there are specialized functions to return detailed information about the mouseclick. Finally it should be noted, that <code class="function">inkey$</code> will only register mouseclicks within the graphic-window; mouseclicks in the text-window cannot be detected.</p><p><code class="function">inkey$</code> accepts an optional argument, specifying a timeout in seconds; if no key has been pressed within this span of time, an empty string is returned. If the timeout-argument is omitted, <code class="function">inkey$</code> will wait for ever.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2526592"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
open window 100,100
print "Press any key or press 'q' to stop."
repeat
  a$=inkey$
  print a$
until(a$="q")
          </pre><p>This program simply returns the key pressed. You may use it, to learn, which strings are returned for the special keys on your keyboard (e.g. function-keys).</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2526616"></a><h2>See also</h2><p><code class="function"><a href="#ref_clear_screen" title="clear screen">clear screen</a></code>,<code class="function"><a href="#ref_mousex" title="mousex">mousex</a></code>, <code class="function"><a href="#ref_mousey" title="mousey">mousey</a></code>, <code class="function"><a href="#ref_mouseb" title="mouseb">mouseb</a></code>, <code class="function"><a href="#ref_mousemod" title="mousemod">mousemod</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_input"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>input — read input from the user (or from a file) and assign it to a variable</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
input a
input a,b,c
input a$
input "Hello" a
input #1 a$
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2526710"></a><h2>Description</h2><p><code class="function">input</code> reads the new contents of one or many (numeric- or string-) variables, either from the keyboard (i.e. from <span class="emphasis"><em>you</em></span>) or from a file. An optional first string-argument specifies a prompt, which will be issued before reading any contents.</p><p>If you want to read from an open file, you need to specify a hash ('#'), followed by the number, under which the file has been opened.</p><p>Note, that the input is split at spaces, i.e. if you enter a whole line consisting of many space-separated word, the first <code class="function">input</code>-statement will only return the first word; the other words will only be returned on subsequent calls to <code class="function">input</code>; the same applies, if a single <code class="function">input</code> reads multiple variables: The first variable gets only the first word, the second one the second word, and so on. If you don't like this behaviour, you may use <code class="function">line input</code>, which returns a whole line (including embedded spaces) at once.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2526772"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter the name of a file to read: " a$
open 1,a$
while(!eof(1))
  input #1 b$
  print b$
wend
          </pre><p>If this program is stored within a file <code class="filename">test.yab</code> and you enter this name when prompted for a file to read, you will see this output:</p><pre class="screen">Please enter the name of a file to read: t.yab
input
"Please
enter
the
name
of
a
file
to
read:
"
a$
open
1,a$
while(!eof(1))
input
#1
b$
print
b$
wend
</pre><p>
</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2526812"></a><h2>See also</h2><p><code class="function"><a href="#ref_line_input" title="line input">line input</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_instr"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>instr() — searches its second argument within the first; returns its position if found</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print instr(a$,b$)
if (instr(a$,b$)) …
pos=instr(a$,b$,x)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2526865"></a><h2>Description</h2><p>The <code class="function">instr</code>-functions requires two string arguments and searches the second argument within the first. If the second argument can be found within the first, the position is returned (counting from one). If it can not be found, the <code class="function">instr</code>-function returns 0; this makes this function usable within the condition of an <code class="function">if</code>-statement (see the example below).</p><p>If you supply a third, numeric argument to the <code class="function">instr</code>-function, it will be used as a starting point for the search. Therefore <code class="function">instr("abcdeabcdeabcde","e",8)</code> will return 10, because the search for an "<code class="literal">e</code>" starts at position 8 and finds the "<code class="literal">e</code>" at position 10 (and not the one at position 5).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2526928"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a text containing the string 'bumf': " a$
if (instr(a$,"bumf")) then
  print "Well done !"
else
  print "not so well ..."
endif
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2526946"></a><h2>See also</h2><p><code class="function"><a href="#ref_rinstr" title="rinstr()">rinstr</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_int"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>int() — return the integer part of its single numeric argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print int(a)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2526999"></a><h2>Description</h2><p>The <code class="function">int</code>-function returns only the digits before the comma; <code class="function">int(2.5)</code> returns <code class="computeroutput">2</code> and <code class="function">int(-2.3)</code> returns <code class="computeroutput">-2</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527039"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a whole number between 1 and 10: " a
if (a=int(a) and a&gt;=1 and a&lt;=10) then
  print "Thanx !"
else
  print "Never mind ..."
endif
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527062"></a><h2>See also</h2><p><code class="function"><a href="#ref_frac" title="frac()">frac</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_l"></a>L</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_label">label</a></span><span class="refpurpose"> - mark a specific location within your program for goto, gosub or restore</span></dt><dt><span class="refentrytitle"><a href="#ref_left">left$()</a></span><span class="refpurpose"> - return (or change) left end of a string</span></dt><dt><span class="refentrytitle"><a href="#ref_len">len()</a></span><span class="refpurpose"> - return the length of a string</span></dt><dt><span class="refentrytitle"><a href="#ref_line">line</a></span><span class="refpurpose"> - draw a line</span></dt><dt><span class="refentrytitle"><a href="#ref_line_input">line input</a></span><span class="refpurpose"> - read in a whole line of text and assign it to a variable</span></dt><dt><span class="refentrytitle"><a href="#ref_local">local</a></span><span class="refpurpose"> - mark a variable as local to a subroutine</span></dt><dt><span class="refentrytitle"><a href="#ref_log">log()</a></span><span class="refpurpose"> - compute the natural logarithm</span></dt><dt><span class="refentrytitle"><a href="#ref_loop">loop</a></span><span class="refpurpose"> - marks the end of an infinite loop</span></dt><dt><span class="refentrytitle"><a href="#ref_lower">lower$()</a></span><span class="refpurpose"> - convert a string to lower case</span></dt><dt><span class="refentrytitle"><a href="#ref_ltrim">ltrim$()</a></span><span class="refpurpose"> - trim spaces at the left end of a string</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_label"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>label — mark a specific location within your program for <code class="function">goto</code>, <code class="function">gosub</code> or <code class="function">restore</code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
label foo

…

goto foo
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527143"></a><h2>Description</h2><p>The <code class="function">label</code>-command can be used to give a name to a specific location within your program. Such a position might be referred from one of three commands: <code class="function">goto</code>, <code class="function">gosub</code> and <code class="function">restore</code>.</p><p>You may use labels safely within libraries, because a label (e.g. <code class="computeroutput">foo</code>) does not collide with a label with the same name within the main program or within another library; <span class="application">yabasic</span> will not mix them up.</p><p>As an aside, please note, that line numbers are a special (however deprecated) case of labels; see the second example below.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527202"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 100
  if (rand(10)&gt;5) goto done
next a
label done

10 for a=1 to 100
20   if (rand(10)&gt;5) goto 40
30 next a
40
          </pre><p>Within this example, the <code class="function">for</code>-loop will probably be left prematurely with a <code class="function">goto</code>-statement. This task is done <span class="emphasis"><em>twice</em></span>: First with labels and then again with line numbers.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527241"></a><h2>See also</h2><p><code class="function"><a href="#ref_gosub" title="gosub">gosub</a></code>, <code class="function"><a href="#ref_goto" title="goto">goto</a></code>.</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_left"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>left$() — return (<span class="emphasis"><em>or change</em></span>) left end of a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print left$(a$,2)
left$(b$,3)="foobar"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527307"></a><h2>Description</h2><p>The <code class="function">left$</code>-function accepts two arguments (a string and a number) and returns the part from the left end of the string, whose length is specified by its second argument. Loosely spoken, it simply returns the requested number of chars from the left end of the given string.</p><p>Note, that the <code class="function">left$</code>-function can be assigned to, i.e. it may appear on the left hand side of an assignment. In this way it is possible to change a part of the variable used within the <code class="function">left$</code>-function. Note, that that way the <span class="emphasis"><em>length</em></span> of the string cannot be changed, i.e. characters might be overwritten, but not added. For an example see below.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527351"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please answer yes or no: " a$
l=len(a$):a$=lower$(a$):print "Your answer is ";
if (left$("yes",l)=a$ and l&gt;=1) then
  print "yes"
elsif (left$("no",l)=a$ and l&gt;=1) then
  print "no"
else
  print "?"
endif
          </pre><p>This example asks a simple yes/no question and goes some way to accept even incomplete input, while still being able to reject invalid input.</p><p>This second example demonstrates the capability to <span class="emphasis"><em>assign</em></span> to the <code class="function">left$</code>-function.</p><pre class="programlisting">
a$="Heiho World !"
print a$
left$(a$,5)="Hello"
print a$
</pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527397"></a><h2>See also</h2><p><code class="function"><a href="#ref_right" title="right$()">right$</a></code>, <code class="function"><a href="#ref_mid" title="mid$()">mid$</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_len"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>len() — return the length of a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=len(a$)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527458"></a><h2>Description</h2><p>The <code class="function">len</code>-function returns the length of its single string argument.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527475"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a password: " a$
if (len(a$)&lt;6) error "Password too short !"
          </pre><p>This example checks the length of the password, that the user has entered.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527496"></a><h2>See also</h2><p><code class="function"><a href="#ref_left" title="left$()">left$</a></code>, <code class="function"><a href="#ref_right" title="right$()">right$</a></code> and <code class="function"><a href="#ref_mid" title="mid$()">mid$</a></code>, </p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_line"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>line — draw a line</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open window 100,100
line 0,0,100,100
line 0,0 to 100,100
new curve
line 100,100
line to 100,100

open window 100,100
clear line 0,0,100,100
clear line 0,0 to 100,100
new curve
clear line 100,100
clear line to 100,100
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527571"></a><h2>Description</h2><p>The <code class="function">line</code>-command draws a line. Simple as this is, the <code class="function">line</code>-command has a large variety of forms as they are listed in the synopsis above. Lets look at them a little closer:</p><div class="itemizedlist"><ul type="disc"><li><p>A line has a starting and an end point; therefore the <code class="function">line</code>-command (normally) needs four numbers as arguments, representing these two points. This is the first form appearing within the synopsis. </p></li><li><p>You may separate the two points with either '<code class="computeroutput">,</code>' or <code class="function">to</code>, which accounts for the second form of the <code class="function">line</code>-command.</p></li><li><p>The <code class="function">line</code>-command may be used to draw a connected sequence of lines with a sequence of commands like <code class="function">line x,y</code>; Each command will draw a line from the point where the last <code class="function">line</code>-command left off, to the point specified in the arguments. Note, that you need to use the command <code class="function">new curve</code> before you may issue such a <code class="function">line</code>-command. See the example below.</p></li><li><p>You may insert the word <code class="function">to</code> for beauty: <code class="function">line to x,y</code>, which does exactly the same as <code class="function">line x,y</code></p></li><li><p>Finally, you may choose not to draw, but to erase the lines; this can be done by prepending the phrase <code class="function">clear</code>. This account for all the other forms of the <code class="function">line</code>-command.</p></li></ul></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527726"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
line 10,10 to 10,190
line 10,190 to 190,190
new curve
for a=0 to 360
  line to 10+a*180/360,100+60*sin(a*pi/180)
next a
          </pre><p>This example draws a sine-curve (with an offset in x- and y-direction). Note, that the first <code class="function">line</code>-command after <code class="function">new curve</code> does not draw anything. Only the coordinates will be stored. The second iteration of the loop then uses these coordinates as a starting point for the first line.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527764"></a><h2>See also</h2><p><code class="function"><a href="#ref_new_curve" title="new curve">new curve</a></code>, <code class="function"><a href="#ref_close_curve" title="close curve">close curve</a></code>, <code class="function"><a href="#ref_open_window" title="open window">open window</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_line_input"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>line input — read in a whole line of text and assign it to a variable</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
line input a
line input a$
line input "Hello" a
line input #1 a$
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527838"></a><h2>Description</h2><p>In most respects <code class="function">line input</code> is like the <code class="function"><a href="#ref_input" title="input">input</a></code>-command: It reads the new contents of a variable, either from keyboard or from a file. However, <code class="function">line input</code> always reads a complete line and assigns it to its variable. <code class="function">line input</code> does not stop reading at spaces and is therefore the best way to read in a string which might contain whitespace. Note, that the final newline is stripped of.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527881"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
line input "Please enter your name (e.g. Frodo Beutelin): " a$
print "Hello ",a$
          </pre><p>Note that the usage of <code class="function">line input</code> is essential in this example; a simple <code class="function">input</code>-statement would only return the string up to the first space, e.g. <code class="computeroutput">Frodo</code>.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527922"></a><h2>See also</h2><p><code class="function"><a href="#ref_input" title="input">input</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_local"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>local — mark a variable as local to a subroutine</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
sub foo()

  local a,b,c$,d(10),e$(5,5)

  …

end sub 
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2527974"></a><h2>Description</h2><p>The <code class="function">local</code>-command can (and should be) used to mark a variable (or array) as <span class="emphasis"><em>local</em></span> to the containing subroutine. This means, that a local variable in your subroutine is totally different from a variable with the same name within your main program. Variables which are known everywhere within your program are called <span class="emphasis"><em>global</em></span> in contrast.</p><p>Declaring variables within the subroutine as <span class="emphasis"><em>local</em></span> helps to avoid hard to find bugs; therefore local variables should be used whenever possible.</p><p>Note, that the parameters of your subroutines are always local.</p><p>As you may see from the example, local arrays may be created without using the keyword <code class="function">dim</code> (which is required only for global arrays).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528026"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
a=1
b=1
print a,b
foo()
print a,b

sub foo()
  local a
  a=2
  b=2
end sub
          </pre><p>This example demonstrates the difference between <code class="function">local</code> and global variables; it produces this output:</p><p>
</p><pre class="screen">1 1
1 2
</pre><p>
</p><p>As you may see, the content of the global variable <code class="function">a</code> is unchanged after the subroutine <code class="function">foo</code>; this is because the assignment <code class="computeroutput">a=2</code> within the subroutine affects the <span class="emphasis"><em>local</em></span> variable <code class="computeroutput">a</code> only and not the global one. However, the variable <code class="computeroutput">b</code> is never declared local and therefore the subroutine changes the global variable, which is reflected in the output of the second print-statement.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528104"></a><h2>See also</h2><p><code class="function"><a href="#ref_sub" title="sub">sub</a></code>, <code class="function"><a href="#ref_static" title="static">static</a></code>, <code class="function"><a href="#ref_dim" title="dim">dim</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_log"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>log() — compute the natural logarithm</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a=log(x)
a=log(x,base)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528174"></a><h2>Description</h2><p>The <code class="function">log</code>-function computes the logarithm of its first argument. The optional second argument gives the base for the logarithm; if this second argument is omitted, the <span class="emphasis"><em>euler</em></span>-constant 2.71828… will be taken as the base.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528198"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
for x=10 to 190 step 10:for y=10 to 190 step 10
  r=3*log(1+x,1+y)
  if (r&gt;10) r=10
  if (r&lt;1) r=1
  fill circle x,y,r
next y:next x
          </pre><p>This draws another nice plot.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528220"></a><h2>See also</h2><p><code class="function"><a href="#ref_exp" title="exp()">exp</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_loop"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>loop — marks the end of an infinite loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
do
  …
loop
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528271"></a><h2>Description</h2><p>The <code class="function">loop</code>-command marks the ends of a loop (which is started by <code class="function">do</code>), wherein all statements within the loop are repeated forever. In this respect the <code class="function">do loop</code>-loop is infinite, however, you may leave it anytime via <code class="function">break</code> or <code class="function">goto</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528313"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "Hello, I will throw dice, until I get a 2 ..."
do
  r=int(rand(6))+1
  print r
  if (r=2) break
loop
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528330"></a><h2>See also</h2><p><code class="function"><a href="#ref_do" title="do">do</a></code>, <code class="function"><a href="#ref_for" title="for">for</a></code>, <code class="function"><a href="#ref_repeat" title="repeat">repeat</a></code>, <code class="function"><a href="#ref_while" title="while">while</a></code>, <code class="function"><a href="#ref_break" title="break">break</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_lower"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>lower$() — convert a string to lower case</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
l$=lower$(a$)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528421"></a><h2>Description</h2><p>The <code class="function">lower$</code>-function accepts a single string-argument and converts it to all lower case.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528438"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a password: " a$
if (a$=lower$(a$)) error "Your password is NOT mixed case !"
          </pre><p>This example prompts for a password and checks, if it is really lower case.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528460"></a><h2>See also</h2><p><code class="function"><a href="#ref_upper" title="upper$()">upper$</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_ltrim"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>ltrim$() — trim spaces at the left end of a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a$=ltrim$(b$)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528511"></a><h2>Description</h2><p>The <code class="function">ltrim$</code>-function removes all whitespace from the left end of a string and returns the result.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528529"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please answer 'yes' or 'no' : " a$
a$=lower$(ltrim$(rtrim$(a$)))
if (len(a$)&gt;0 and a$=left$("yes",len(a$))) then
  print "Yes ..."
else
  print "No ..."
endif
          </pre><p>This example prompts for an answer and removes any spaces, which might precede the input; therefore it is even prepared for the (albeit somewhat pathological case, that the user first hits <span class="emphasis"><em>space</em></span> before entering his answer.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528564"></a><h2>See also</h2><p><code class="function"><a href="#ref_rtrim" title="rtrim$()">rtrim$</a></code>, <code class="function"><a href="#ref_trim" title="trim$()">trim$</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_m"></a>M</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_max">max()</a></span><span class="refpurpose"> - return the larger of its two arguments</span></dt><dt><span class="refentrytitle"><a href="#ref_mid">mid$()</a></span><span class="refpurpose"> - return (or change) characters from within a string</span></dt><dt><span class="refentrytitle"><a href="#ref_min">min()</a></span><span class="refpurpose"> - return the smaller of its two arguments</span></dt><dt><span class="refentrytitle"><a href="#ref_mod">mod()</a></span><span class="refpurpose"> - compute the remainder of a division</span></dt><dt><span class="refentrytitle"><a href="#ref_mouseb">mouseb</a></span><span class="refpurpose"> - extract the state of the mousebuttons from a string returned by inkey$</span></dt><dt><span class="refentrytitle"><a href="#ref_mousemod">mousemod</a></span><span class="refpurpose"> - return the state of the modifier keys during a mouseclick</span></dt><dt><span class="refentrytitle"><a href="#ref_mousex">mousex</a></span><span class="refpurpose"> - return the x-position of a mouseclick</span></dt><dt><span class="refentrytitle"><a href="#ref_mousey">mousey</a></span><span class="refpurpose"> - return the y-position of a mouseclick</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_max"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>max() — return the larger of its two arguments</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print max(a,b)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528638"></a><h2>Description</h2><p>Return the <span class="emphasis"><em>maximum</em></span> of its two arguments.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528652"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
dim m(10)
for a=1 to 1000
  m=0
  For b=1 to 10
    m=max(m,ran(10))
  next b
  m(m)=m(m)+1
next a

for a=1 to 9
  print a,": ",m(a)
next a
          </pre><p>Within the inner <code class="function">for</code>-loop (the one with the loop-variable <code class="function">b</code>), the example computes the maximum of 10 random numbers. The outer loop (with the loop variable <code class="function">a</code>) now repeats this process 1000 times and counts, how often each maximum appears. The last loop finally reports the result.</p><p>Now, the interesting question would be, which will be approached, when we increase the number of iterations from thousand to infinity. Well, maybe someone could just tell me <code class="computeroutput">:-)</code></p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528705"></a><h2>See also</h2><p><code class="function"><a href="#ref_min" title="min()">min</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_mid"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>mid$() — return (<span class="emphasis"><em>or change</em></span>) characters from within a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print mid$(a$,2,1)
print mid$(a$,2)
mid$(a$,5,3)="foo"
mid$(a$,5)="foo"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528760"></a><h2>Description</h2><p>The <code class="function">mid$</code>-function requires three arguments: a string and two numbers, where the first number specifies a position within the string and the second one gives the number of characters to be returned; if you omit the second argument, the <code class="function">mid$</code>-function returns all characters up to the end of the string.</p><p>Note, that you may assign to the <code class="function">mid$</code>-function, i.e. <code class="function">mid$</code> may appear on the left hand side of an assignment. In this way it is possible to change a part of the variable used within the <code class="function">mid$</code>-function. Note, that that way the <span class="emphasis"><em>length</em></span> of the string cannot be changed, i.e. characters might be overwritten, but not added. For an example see below.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528817"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a string: " a$
for a=1 to len(a$)
  if (instr("aeiou",lower$(mid$(a$,a,1)))) mid$(a$,a,1)="e"
next a
print "When you turn everything to lower case and"
print "replace every vowel with 'e', your input reads:"
print
print a$
          </pre><p>This example transforms the input string a bit, using the <code class="function">mid$</code>-function to retrieve a character from within the string as well as to change it.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528848"></a><h2>See also</h2><p><code class="function"><a href="#ref_left" title="left$()">left$</a></code> and <code class="function"><a href="#ref_right" title="right$()">right$</a></code>.</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_min"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>min() — return the smaller of its two arguments</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print min(a,b)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528911"></a><h2>Description</h2><p>Return the <span class="emphasis"><em>minimum</em></span> of its two argument.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528925"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
dim m(10)
for a=1 to 1000
  m=min(ran(10),ran(10))
  m(m)=m(m)+1
next a

for a=1 to 9
  print a,": ",m(a)
next a
          </pre><p>For each iteration of the loop, the lower of two random number is recorded. The result is printed at the end.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528948"></a><h2>See also</h2><p><code class="function"><a href="#ref_max" title="max()">max</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_mod"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>mod() — compute the remainder of a division</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print mod(a,b)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2528998"></a><h2>Description</h2><p>The <code class="function">mod</code>-function divides its two arguments and computes the remainder. Note, that <code class="literal">a/b-int(a/b)</code> and <code class="literal">mod(a,b)</code> are always equal.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529028"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
print at(10,10) "Please wait ";
p$="-\|/"
for a=1 to 100
  rem  ... do something lengthy here, or simply sleep :-)
  pause(1)
  print at(22,10) mid$(p$,1+mod(a,4))
next a
          </pre><p>This example executes some time consuming action within a loop (in fact, it simply sleeps) and gives the user some indication of progress by displaying a turning bar (thats where the <code class="function">mod()</code>-function comes into play).</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529059"></a><h2>See also</h2><p><code class="function"><a href="#ref_int" title="int()">int</a></code>, <code class="function"><a href="#ref_frac" title="frac()">frac</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_mouseb"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>mouseb — extract the state of the mousebuttons from a string returned by <code class="function">inkey$</code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
inkey$
print mouseb()
print mouseb
a$=inkey$
print mouseb(a$)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529126"></a><h2>Description</h2><p>The <code class="function">mouseb</code>-function is a helper function for decoding part of the (rather complicated) strings, which are returned by the <code class="function">inkey$</code>-function. If a mousebutton has been pressed, the <code class="function">mouseb</code>-function returns the number (1,2 or 3) of the mousebutton, when it is pressed and returns its negative (-1,-2 or -3), when it is released.</p><p>The <code class="function">mouseb</code>-function accepts zero or one arguments. A single argument should be a string returned by the <code class="function">inkey$</code>-function; if <code class="function">mouseb</code> is called without any arguments, it returns the values from the last call to <code class="function">inkey$</code>, which are stored implicitly and internally by <span class="application">yabasic</span>.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Note however, that the value returned by the <code class="function">mouseb</code>-function does <span class="emphasis"><em>not</em></span> reflect the <span class="emphasis"><em>current</em></span> state of the mousebuttons. It rather extracts the information from the string passed as an argument (or from the last call to the <code class="function">inkey$</code>-function, if no argument is passed). So the value returned by <code class="function">mouseb</code> reflects the state of the mousebuttons at the time the <code class="function">inkey$</code>-function has been called; as opposed to the time the <code class="function">mouseb</code>-function is called.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529244"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
clear screen
print "Please draw lines; press (and keep it pressed)" 
print "the left mousebutton for the starting point,"
print "release it for the end-point."
do
  if (mouseb(release$)=1) press$=release$
  release$=inkey$
  if (mouseb(release$)=-1) then
    line mousex(press$),mousey(press$) to mousex(release$),mousey(release$)
  endif
loop
          </pre><p>This is a maybe the most simplistic line-drawing program possible, catching presses as well as releases of the first mousebutton.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529272"></a><h2>See also</h2><p><code class="function"><a href="#ref_inkey" title="inkey$">inkey$</a></code>, <code class="function"><a href="#ref_mousex" title="mousex">mousex</a></code>, <code class="function"><a href="#ref_mousey" title="mousey">mousey</a></code> and <code class="function"><a href="#ref_mousemod" title="mousemod">mousemod</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_mousemod"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>mousemod — return the state of the modifier keys during a mouseclick</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
inkey$
print mousemod()
print mousemod
a$=inkey$
print mousemod(a$)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529355"></a><h2>Description</h2><p>The <code class="function">mousemod</code>-function is a helper function for decoding part of the (rather complicated) strings, which are returned by the <code class="function">inkey$</code>-function if a mousebutton has been pressed. It returns the state of the keyboard modifiers (<code class="literal">shift</code>, <code class="literal">ctrl</code> or <code class="literal">alt</code>): If the <code class="literal">shift</code>-key is pressed, <code class="function">mousemod</code> returns 1, for the <code class="literal">alt</code>-key 2 and for the <code class="literal">ctrl</code>-key 4. If more than one key is pressed, the sum of these values is returned, e.g. <code class="function">mousemod</code> returns 5, if <code class="literal">shift</code> and <code class="literal">ctrl</code> are pressed simultaneously.</p><p>The <code class="function">mousemod</code>-function accepts zero or one arguments. A single argument should be a string returned by the <code class="function">inkey$</code>-function; if <code class="function">mousemod</code> is called without any arguments, it returns the values from the last call to <code class="function">inkey$</code> (which are stored implicitly and internally by yabasic).</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Please see also the Note within the <code class="function"><a href="#ref_mouseb" title="mouseb">mouseb</a></code>-function.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529490"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
clear screen
do
  a$=inkey$
  if (left$(a$,2)="MB") then
    x=mousex(a$)
    y=mousey(a$)
    if (mousemod(a$)=0) then
      circle x,y,20
    else
      fill circle x,y,20
    endif
  endif
loop
          </pre><p>This program draws a circle, whenever a mousebutton is pressed; the circles are filled, when any modifier is pressed, and empty if not.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529515"></a><h2>See also</h2><p><code class="function"><a href="#ref_inkey" title="inkey$">inkey$</a></code>, <code class="function"><a href="#ref_mousex" title="mousex">mousex</a></code>, <code class="function"><a href="#ref_mousey" title="mousey">mousey</a></code> and <code class="function"><a href="#ref_mouseb" title="mouseb">mouseb</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_mousex"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>mousex — return the x-position of a mouseclick</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
inkey$
print mousex()
print mousex
a$=inkey$
print mousex(a$)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529597"></a><h2>Description</h2><p>The <code class="function">mousex</code>-function is a helper function for decoding part of the (rather complicated) strings, which are returned by the <code class="function">inkey$</code>-function; It returns the x-position of the mouse as encoded within its argument.</p><p>The <code class="function">mousex</code>-function accepts zero or one arguments. A single argument should be a string returned by the <code class="function">inkey$</code>-function; if <code class="function">mousex</code> is called without any arguments, it returns the values from the last call to <code class="function">inkey$</code> (which are stored implicitly and internally by yabasic).</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Please see also the Note within the <code class="function"><a href="#ref_mouseb" title="mouseb">mouseb</a></code>-function.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529671"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
clear screen
do
  a$=inkey$
  if (left$(a$,2)="MB") then
    line mousex,0 to mousex,200
  endif
loop
          </pre><p>This example draws vertical lines at the position, where the mousebutton has been pressed.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529693"></a><h2>See also</h2><p><code class="function"><a href="#ref_inkey" title="inkey$">inkey$</a></code>, <code class="function"><a href="#ref_mousemod" title="mousemod">mousemod</a></code>, <code class="function"><a href="#ref_mousey" title="mousey">mousey</a></code> and <code class="function"><a href="#ref_mouseb" title="mouseb">mouseb</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_mousey"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>mousey — return the y-position of a mouseclick</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
inkey$
print mousey()
print mousey
a$=inkey$
print mousey(a$)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529775"></a><h2>Description</h2><p>The <code class="function">mousey</code>-function is a helper function for decoding part of the (rather complicated) strings, which are returned by the <code class="function">inkey$</code>-function. <code class="function">mousey</code> returns the y-position of the mouse as encoded within its argument.</p><p>The <code class="function">mousey</code>-function accepts zero or one arguments. A single argument should be a string returned by the <code class="function">inkey$</code>-function; if <code class="function">mousey</code> is called without any arguments, it returns the values from the last call to <code class="function">inkey$</code> (which are stored implicitly and internally by yabasic).</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>Please see also the Note within the <code class="function"><a href="#ref_mouseb" title="mouseb">mouseb</a></code>-function.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529855"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
clear screen
do
  a$=inkey$
  if (left$(a$,2)="MB") then
    line 0,mousey to 200,mousey
  endif
loop
          </pre><p>This example draws horizontal lines at the position, where the mousebutton has been pressed.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529878"></a><h2>See also</h2><p><code class="function"><a href="#ref_inkey" title="inkey$">inkey$</a></code>, <code class="function"><a href="#ref_mousemod" title="mousemod">mousemod</a></code>, <code class="function"><a href="#ref_mousey" title="mousey">mousex</a></code> and <code class="function"><a href="#ref_mouseb" title="mouseb">mouseb</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_n"></a>N</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_new_curve">new curve</a></span><span class="refpurpose"> - start a new curve, that will be drawn with the line-command</span></dt><dt><span class="refentrytitle"><a href="#ref_next">next</a></span><span class="refpurpose"> - mark the end of a for loop</span></dt><dt><span class="refentrytitle"><a href="#ref_not">not</a></span><span class="refpurpose"> - negate an expression; can be written as !</span></dt><dt><span class="refentrytitle"><a href="#ref_numparams">numparams</a></span><span class="refpurpose"> - return the number of parameters, that have been passed to a subroutine</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_new_curve"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>new curve — start a new curve, that will be drawn with the <code class="function">line</code>-command</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
new curve
line to x,y
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2529978"></a><h2>Description</h2><p>The <code class="function">new curve</code>-function starts a new sequence of lines, that will be drawn by repeated <code class="function">line to</code>-commands.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530001"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
ellipse(100,50,30,60)
ellipse(150,100,60,30)
sub ellipse(x,y,xr,yr)
  new curve
  for a=0 to 2*pi step 0.2
    line to x+xr*cos(a),y+yr*sin(a)
  next a
  close curve
end sub
  
          </pre><p>This example defines a subroutine <code class="function">ellipse</code> that draws an ellipse. Within this subroutine, the ellipse is drawn as a sequence of lines started with the <code class="function">new curve</code> command and closed with <code class="function">close curve</code>.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530044"></a><h2>See also</h2><p><code class="function"><a href="#ref_line" title="line">line</a></code>, <code class="function"><a href="#ref_close_curve" title="close curve">close curve</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_next"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>next — mark the end of a for loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
for a=1 to 10
next a
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530105"></a><h2>Description</h2><p>The <code class="function">next</code>-keyword marks the end of a <code class="function">for</code>-loop. All statements up to the <code class="function">next</code>-keyword will be repeated as specified with the <code class="function">for</code>-clause. Note, that the name of the variable is optional; so instead of <code class="literal">next a</code> you may write <code class="literal">next</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530153"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 300000
  for b=1 to 21+20*sin(pi*a/20)
    print "*";
  next b
  print
  sleep 0.1
next a
          </pre><p>This example simply plots a sine-curve until you fall asleep.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530175"></a><h2>See also</h2><p><code class="function"><a href="#ref_for" title="for">for</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_not"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>not — negate an expression; can be written as <code class="function">!</code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (not a&lt;b) then …
bad=!okay
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530231"></a><h2>Description</h2><p>The keyword <code class="function">not</code> (or <code class="function">!</code> for short) is mostly used within conditions (e.g. within <code class="function">if</code>- or <code class="function">while</code>-statements). There it is employed to negate the condition or expression (i.e. turn <code class="literal">TRUE</code> into <code class="literal">FALSE</code> and vice versa)</p><p>However <code class="function">not</code> can be used within arithmetic calculations too., simply because there is no difference between arithmetic and logical expressions.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530289"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter three ascending numbers: " a,b,c
if (not (a&lt;b and b&lt;c)) error " the numbers you have entered are not ascending ..."
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530312"></a><h2>See also</h2><p><a href="#ref_logical_and" title="and"><code class="function">and</code></a>,<a href="#ref_logical_or" title="logical or"><code class="function">or</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_numparams"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>numparams — return the number of parameters, that have been passed to a subroutine</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
sub foo(a,b,c)
  if (numparams=1) …
  …
end sub
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530375"></a><h2>Description</h2><p>Within a subroutine the local variable <code class="function">numparam</code> or <code class="function">numparams</code> contains the number of parameters, that have been passed to the subroutine. This information can be useful, because the subroutine may have been called with fewer parameters than actually declared. The number of values that actually have been passed while calling the subroutine, can be found in <code class="function">numparams</code>.</p><p>Note, that arguments which are used in the definition of a subroutine but are left out during a call to it (thereby reducing the value of <code class="function">numparams</code>) receive a value of <code class="literal">0</code> or <code class="literal">""</code> (empty string) respectively.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530431"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
a$="123456789"
print part$(a$,4)
print part$(a$,3,7)

sub part$(a$,f,t)
  if (numparams=2) then
    return mid$(a$,f)
  else 
    return mid$(a$,f,t-f+1)
  end if
end sub
          </pre><p>When you run this example, it will print <code class="computeroutput">456789</code> and <code class="computeroutput">34567</code>. Take a look at the subroutine <code class="function">part$</code>, which returns part of the string which has been passed as an argument. If (besides the string) two numbers are passed, they define the starting and end position of the substring, that will be returned. However, if only one number is passed, the rest of the string, starting from this position will be returned. Each of these cases is recognized with the help of the <code class="function">numparams</code> variable.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530484"></a><h2>See also</h2><p><code class="function"><a href="#ref_sub" title="sub">sub</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_o"></a>O</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_on_gosub">on gosub</a></span><span class="refpurpose"> - jump to one of multiple gosub-targets</span></dt><dt><span class="refentrytitle"><a href="#ref_on_goto">on goto</a></span><span class="refpurpose"> - jump to one of many goto-targets</span></dt><dt><span class="refentrytitle"><a href="#ref_on_interrupt">on interrupt</a></span><span class="refpurpose"> - change reaction on keyboard interrupts</span></dt><dt><span class="refentrytitle"><a href="#ref_open">open</a></span><span class="refpurpose"> - open a file</span></dt><dt><span class="refentrytitle"><a href="#ref_open_printer">open printer</a></span><span class="refpurpose"> - open printer for printing graphics</span></dt><dt><span class="refentrytitle"><a href="#ref_open_window">open window</a></span><span class="refpurpose"> - open a graphic window</span></dt><dt><span class="refentrytitle"><a href="#ref_logical_or">logical or</a></span><span class="refpurpose"> - logical or, used in conditions</span></dt><dt><span class="refentrytitle"><a href="#ref_arithmetic_or">or()</a></span><span class="refpurpose"> - arithmetic or, used for bit-operations</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_on_gosub"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>on goto — jump to one of multiple <code class="function">gosub</code>-targets</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
on a gosub foo,bar,baz
  …
label foo
  …
return

label bar
  …
return

label baz
  …
return
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530555"></a><h2>Description</h2><p>The <code class="function">on gosub</code> statement uses its numeric argument (the one between <code class="function">on</code> and <code class="function">gosub</code>) to select an element from the list of labels, which follows after the <code class="function">gosub</code>-keyword: If the number is 1, the program does a <code class="function">gosub</code> to the first label; if the number is 2, to the second and, so on. if the number is zero or less, the program continues at the position of the first label; if the number is larger than the total count of labels, the execution continues at the position of the last label; i.e. the first and last label in the list constitute some kind of fallback-slot.</p><p>Note, that the <code class="function">on gosub</code>-command can no longer be considered <span class="emphasis"><em>state of the art</em></span>; people (not me !) may even start to mock you, if you use it.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530618"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
do
  print "Please enter a number between 1 and 3: "
  print
  input "Your choice " a
  on a gosub bad,one,two,three,bad
loop

label bad
  print "No. Please between 1 and 3"
return

label one
  print "one"
return

label two
  print "two"
return

label three
  print "three"
return
          </pre><p>Note, how invalid input (a number less than 1, or larger than 3) is automatically detected.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530644"></a><h2>See also</h2><p><code class="function"><a href="#ref_goto" title="goto">goto</a></code>, <code class="function"><a href="#ref_on_gosub" title="on gosub">on gosub/function&gt;</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_on_goto"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>on goto — jump to one of many <code class="function">goto</code>-targets</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
on a goto foo,bar,baz
  …
label foo
  …
label bar
  …
label baz
  …
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530712"></a><h2>Description</h2><p>The <code class="function">on goto</code> statement uses its numeric argument (the one between <code class="function">on</code> and <code class="function">goto</code> to select an element from the list of labels, which follows after the <code class="function">goto</code>-keyword: If the number is 1, the execution continues at the first label; if the number is 2, at the second, and so on. if the number is zero or less, the program continues at the position of the first label; if the number is larger than the total count of labels, the execution continues at the position of the last label; i.e. the first and last label in the list constitute some kind of fallback-slot.</p><p>Note, that (unlike the <code class="function">goto</code>-command) the <code class="function">on goto</code>-command can no longer be considered <span class="emphasis"><em>state of the art</em></span>; people may (not me !) even start to mock you, if you use it.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530775"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
label over
print "Please Select one of these choices: "
print
print "  1 -- show time"
print "  2 -- show date"
print "  3 -- exit"
print
input "Your choice " a
on a goto over,show_time,show_date,terminate,over

label show_time
  print time$()
goto over

label show_date
  print date$()
goto over

label terminate
exit
          </pre><p>Note, how invalid input (a number less than 1, or larger than 3) is automatically detected; in such a case the question is simply issued again.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530802"></a><h2>See also</h2><p><code class="function"><a href="#ref_goto" title="goto">goto</a></code>, <code class="function"><a href="#ref_on_gosub" title="on gosub">on gosub/function&gt;</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_on_interrupt"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>on interrupt — change reaction on keyboard interrupts</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
on interrupt break
…
on interrupt continue
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530865"></a><h2>Description</h2><p>With the <code class="function">on interrupt</code>-command you may change the way, how yabasic reacts on a keyboard interrupt; it comes in two variants: <code class="function">on interrupt break</code> and <code class="function">on interrupt continue</code>. A keyboard interrupt is produced, if you press <strong class="userinput"><code>ctrl-C</code></strong> on your keyboard; normally (and certainly after you have called <code class="function">on interrupt break</code>), <span class="application">yabasic</span> will terminate with an error message. However after the command <code class="function">on interrupt continue</code> yabasic ignores any keyboard interrupt. This may be useful, if you do not want your program being interruptible during certain critical operations (e.g. updating of files).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530924"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "Please stand by while writing a file with random data ..."
on interrupt continue
open "random.data" for writing as #1
for a=1 to 100
  print #1 ran(100)
  print a," percent done."
  sleep 1
next a
close #1
on interrupt continue
          </pre><p>This program writes a file with 100 random numbers. The <code class="function">on interrupt continue</code> command insures, that the program will not be terminated on a keyboard interrupt and the file will be written entirely in any case. The <code class="function">sleep</code>-command just stretches the process artificially to give you a chance to try a <strong class="userinput"><code>ctrl-C</code></strong>.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2530969"></a><h2>See also</h2><p>There is no related command.</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_open"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>open — open a file</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open a,"file","r"
open #a,"file","w"
open #a,printer
open "file" for reading as a
open "file" for writing as #a
a=open("file")
a=open("file","r")
if (open(a,"file")) …
if (open(a,"file","w")) …
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531012"></a><h2>Description</h2><p>The <code class="function">open</code>-command opens a file for reading or writing or a printer for printing text. <code class="function">open</code> comes in a wide variety of ways; it requires these arguments:</p><div class="variablelist"><dl><dt><span class="term">filenumber</span></dt><dd><p>In the synopsis this is <code class="literal">a</code> or <code class="literal">#a</code>. In <span class="application">yabasic</span> each file is associated with a number between 1 and a maximum value, which depends on the operating system. For historical reasons the filenumber can be preceded by a hash ('<code class="literal">#</code>'). Note, that specifying a filenumber is optional; if it is omitted, the <code class="function">open</code>-function will return a filenumber, which should then be stored in a variable for later reference. This filenumber can be a simple number or an arbitrary complex arithmetic expression, in which case braces might be necessary to save <span class="application">yabasic</span> from getting confused.</p></dd><dt><span class="term">filename</span></dt><dd><p>In the synopsis above this is <code class="literal">"file"</code>. This string specifies the name of the file to open (note the important <a href="#ref_windows_filenames" title="Specifying Filenames under Windows">caveat</a> on specifying these filenames).</p></dd><dt><span class="term">accessmode</span></dt><dd><p>In the synopsis this is <code class="literal">"r"</code>, <code class="literal">"w"</code>, <code class="literal">for reading</code> or <code class="literal">for writing</code>. This string or clause specifies the mode in which the file is opened; it may be one of:
		</p><div class="variablelist"><dl><dt><span class="term">"r"</span></dt><dd><p>Open the file for reading (may also be written as <code class="literal">for reading</code>). If the file does not exist, the command will fail. This mode is the default, i.e. if no mode is specified with the <code class="function">open</code>-command, the file will be opened with this mode.</p></dd><dt><span class="term">"w"</span></dt><dd><p>Open the file for writing (may also be written as <code class="literal">for writing</code>). If the file does not exist, it will be created.</p></dd><dt><span class="term">"a"</span></dt><dd><p>Open the file for appending, i.e. what you write to the file will be appended after its initial contents. If the file does not exist, it will be created.</p></dd><dt><span class="term">"b"</span></dt><dd><p>This letter may not appear alone, but may be combined with the other letters (e.g. <code class="literal">"rb"</code>) to open a file in binary mode (as opposed to text mode).</p></dd></dl></div><p>

	      </p></dd></dl></div><p>As you may see from the synopsis, the <code class="function">open</code>-command may either be called as a command (without braces) or as a function (with braces). If called as a function, it will return the filenumber or zero if the operation fails. Therefore the <code class="function">open</code>-function may be used within the condition of an <code class="function">if</code>-statement.</p><p>If the <code class="function">open</code>-command fails, you may use <code class="function"><a href="#ref_peek" title="peek">peek("error")</a></code> to retrieve the exact nature of the error.</p><p>Furthermore note, that there is another, somewhat separate usage of the <code class="function">open</code>-command; if you specify the bareword <code class="literal">printer</code> instead of a filename, the command opens a printer for printing text. Every text (and only text) you print to this file will appear on your printer. Note, that this is very different from printing graphics, as can be done with <code class="function"><a href="#ref_open_printer" title="open printer">open printer</a></code>.</p><p>Finally you may read the description for <code class="function"><a href="#ref_peek" title="peek">peek("error")</a></code> to learn which errors may have happened during an <code class="function">open</code>-call.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531354"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open "foo.bar" for writing as #1
print #1 "Hallo !"
close #1
if (not open(1,"foo.bar")) error "Could not open 'foo.bar' for reading"
while(not eof(1)) 
  line input #1 a$
  print a$
wend
          </pre><p>This example simply opens the file <code class="literal">foo.bar</code>, writes a single line, reopens it and reads its contents again.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531384"></a><h2>See also</h2><p><code class="function"><a href="#ref_close" title="close">close</a></code>, <code class="function"><a href="#ref_print" title="print">print</a></code>, <code class="function"><a href="#ref_peek" title="peek">peek</a></code>, <code class="function"><a href="#ref_peek" title="peek">peek("error")</a></code> and <code class="function"><a href="#ref_open_printer" title="open printer">open printer</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_open_printer"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>open printer — open printer for printing graphics</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open printer
open printer "file"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531476"></a><h2>Description</h2><p>The <code class="function">open printer</code>-command opens a printer for printing graphics. The command requires, that a graphic window has been opened before. Everything that is drawn into this window will then be sent to the printer too.</p><p>A new piece of paper may be started with the <code class="function">clear window</code>-command; the final (or only) page will appear after the <code class="function">close printer</code>-command.</p><p>Note, that you may specify a filename with <code class="function">open printer</code>; in that case the printout will be sent to a filename instead to a printer. Your program or the user will be responsible for sending this file to the printer afterwards.</p><p>If you use <span class="application">yabasic</span> under Unix, you will need a postscript printer (because <span class="application">yabasic</span> produces postscript output). Alternatively you may use <span class="emphasis"><em>ghostscript</em></span> to transform the postscript file into a form suitable for your printer; but that is beyond the responsibility of <span class="application">yabasic</span>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531554"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
open printer
line 0,0 to 200,200
text 100,100,"Hallo"
close window
close printer
          </pre><p>This example will open a window, draw a line and print some text within; everything will appear on your printer too.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531577"></a><h2>See also</h2><p><code class="function"><a href="#ref_close_printer" title="close printer">close printer</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_open_window"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>open window — open a graphic window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open window x,y
open window x,y,"font"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531629"></a><h2>Description</h2><p>The <code class="function">open window</code>-command opens a window of the specified size. Only one window can be opened at any given moment of time.</p><p>An optional third argument specifies a font to be used for any text within the window. It can however be changed with any subsequent <code class="function"><a href="#ref_text" title="text">text</a></code>-command. </p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531662"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=200 to 400 step 10
  open window a,a
  for b=0 to a
    line 0,b to a,b
    line b,0 to b,a
  sleep 0.1
  close window
next a
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531680"></a><h2>See also</h2><p><code class="function"><a href="#ref_close_window" title="close window">close window</a></code>, <code class="function"><a href="#ref_text" title="text">text</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_logical_or"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>or — logical or, used in conditions</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (a or b) …
while (a or b) …
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531743"></a><h2>Description</h2><p>Used in conditions (e.g within <code class="function"><a href="#ref_if" title="if">if</a></code> or <code class="function"><a href="#ref_while" title="while">while</a></code>) to join two expressions. Returns <code class="constant">true</code>, if either its left or its right or both arguments are <code class="constant">true</code>; returns <code class="constant">false</code> otherwise.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531786"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a number"
if (a&gt;9 or a&lt;1) print "a is not between 1 and 9"
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531805"></a><h2>See also</h2><p><a href="#ref_logical_and" title="and"><code class="function">and</code></a>,<a href="#ref_not" title="not"><code class="function">not</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_arithmetic_or"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>or() — arithmetic or, used for bit-operations</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=or(a,b)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531866"></a><h2>Description</h2><p>Used to compute the bitwise <code class="function">or</code> of both its argument. Both arguments are treated as binary numbers (i.e. a series of 0 and 1); a bit of the resulting value will then be 1, if any of its arguments has 1 at this position in their binary representation.</p><p>Note, that both arguments are silently converted to integer values and that negative numbers have their own binary representation and may lead to unexpected results when passed to <code class="function">or</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531898"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print or(14,3)
          </pre><p>This will print <code class="computeroutput">15</code>. This result is clear, if you note, that the binary representation of 14 and 3 are 1110 and 0011 respectively; this will yield 1111 in binary representation or 15 as decimal.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2531926"></a><h2>See also</h2><p><a href="#ref_arithmetic_and" title="and()"><code class="function">oand</code></a>, <a href="#ref_eor" title="eor()"><code class="function">eor</code></a> and <a href="#ref_not" title="not"><code class="function">not</code></a></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_p"></a>P</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_pause">pause</a></span><span class="refpurpose"> - pause, sleep, wait for the specified number of seconds</span></dt><dt><span class="refentrytitle"><a href="#ref_peek">peek</a></span><span class="refpurpose"> - retrieve various internal informations</span></dt><dt><span class="refentrytitle"><a href="#ref_peek2">peek$</a></span><span class="refpurpose"> - retrieve various internal string-informations</span></dt><dt><span class="refentrytitle"><a href="#ref_pi">pi</a></span><span class="refpurpose"> - a constant with the value 3.14159</span></dt><dt><span class="refentrytitle"><a href="#ref_poke">poke</a></span><span class="refpurpose"> - change selected internals of yabasic</span></dt><dt><span class="refentrytitle"><a href="#ref_print">print</a></span><span class="refpurpose"> - Write to terminal or file</span></dt><dt><span class="refentrytitle"><a href="#ref_print_color">print color</a></span><span class="refpurpose"> - print with color</span></dt><dt><span class="refentrytitle"><a href="#ref_print_colour">print colour</a></span><span class="refpurpose"> - see color</span></dt><dt><span class="refentrytitle"><a href="#ref_putbit">putbit</a></span><span class="refpurpose"> - draw a rectangle of pixels encoded within a string into the graphics window</span></dt><dt><span class="refentrytitle"><a href="#ref_putscreen">putscreen</a></span><span class="refpurpose"> - draw a rectangle of characters into the text terminal</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_pause"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>pause — pause, sleep, wait for the specified number of seconds</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
pause 5
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2532009"></a><h2>Description</h2><p>The <code class="function">pause</code>-command has many different names: You may write <code class="function">pause</code>, <code class="function">sleep</code> or <code class="function">wait</code> interchangeably; whatever you write, <span class="application">yabasic</span> will always do exactly the same.</p><p>The <code class="function">pause</code>-command will simply wait for the specified number of seconds. This may be a fractional number, so you may well wait less than a second. However, if you try to pause for a smaller and smaller interval (e.g. 0.1 seconds, 0.01 seconds, 0.001 seconds and so on) you will find that at some point <span class="application">yabasic</span> will not wait at all. The minimal interval that can be waited depends on the system (Unix, Windows) you are using.</p><p>The <code class="function">pause</code>-command cannot be interrupted. However, sometimes you may want the wait to be interruptible by simply pressing a key on the keyboard. In such cases you should consider using the <code class="function"><a href="#ref_inkey" title="inkey$">inkey$</a></code>-function, with a number of seconds as an argument).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2532096"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
deg=0
do
  maxx=44+40*sin(deg)
  for x=1 to maxx
    print "*";
  next x
  pause 0.1+(maxx*maxx/(4*84*84))
  print
  deg=deg+0.1
loop
          </pre><p>This example draws a sine-curve; due to the <code class="function">pause</code>-statement the speed of drawing varies in the same way as the speed of a ball might vary, if it would roll along this curve under the influence of gravity.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2532126"></a><h2>See also</h2><p><code class="function"><a href="#ref_sleep" title="sleep">sleep</a></code>, <code class="function"><a href="#ref_wait" title="wait">wait</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_peek"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>peek — retrieve various internal informations</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print peek("foo")
a=peek(#1)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2532188"></a><h2>Description</h2><p>The <code class="function">peek</code>-function has many different and mostly unrelated uses. It is a kind of grabbag for retrieving all kinds of numerical information, internal to <span class="application">yabasic</span>. The meaning of the numbers returned be the <code class="function">peek</code>-function depends on the string or number passed as an argument.</p><p><code class="function">peek</code> always returns a number, however the closely related <code class="function"><a href="#ref_peek2" title="peek$">peek$</a></code>-function exists, which may be used to retrieve string information from among the internals of <span class="application">yabasic</span>. Finally note, that some of the values which are retrieved with <code class="function">peek</code> may even be changed, using the <code class="function"><a href="#ref_poke" title="poke">poke</a></code>-function.</p><p>There are two variants of the <code class="function">peek</code>-function: One expects an integer, positive number and is described within the first entry of the list below. The other variant expects one of a well defined set of strings as described in the second and all the following entries of the list below.</p><div class="variablelist"><dl><dt><span class="term"><code class="function">peek(a), peek(#a)</code></span></dt><dd><p>Read a single character from the file <code class="literal">a</code> (which must be open of course).</p></dd><dt><span class="term"><code class="function">peek("winheight")</code></span></dt><dd><p>Return the height of the graphic-window in pixels. If none is open, this <code class="function">peek</code> will return the height of the last window opened or 100, if none has been opened yet.</p></dd><dt><span class="term"><code class="function">peek("winwidth")</code></span></dt><dd><p>Return the width of the graphic-window in pixels. If none is open, this <code class="function">peek</code> will return the width of the last window opened or 100, if none has been opened yet.</p></dd><dt><span class="term"><code class="function">peek("fontheight")</code></span></dt><dd><p>Return the height of the font used within the graphic window. If none is open, this <code class="function">peek</code> will return the height of the last font used or 10, if no window has been opened yet.</p></dd><dt><span class="term"><code class="function">peek("screenheight")</code></span></dt><dd><p>Return the height in characters of the window, wherein yabasic runs. If you have not called <code class="function"><a href="#ref_clear_screen" title="clear screen">clear screen</a></code> yet, this <code class="function">peek</code>will return 0, regardless of the size of your terminal.</p></dd><dt><span class="term"><code class="function">peek("screenwidth")</code></span></dt><dd><p>Return the width in characters of the window, wherein yabasic runs. If you have not called <code class="function"><a href="#ref_clear_screen" title="clear screen">clear screen</a></code> yet, this <code class="function">peek</code>will return 0, regardless of the size of your terminal.</p></dd><dt><span class="term"><code class="function">peek("argument")</code></span></dt><dd><p>Return the number of arguments, that have been passed to <span class="application">yabasic</span> at invocation time. E.g. if <span class="application">yabasic</span> has been called like this: <code class="literal">yabasic foo.yab bar baz</code>, then <code class="function">peek("argument")</code> will return 2. This is because <code class="literal">foo.yab</code> is treated as the name of the program to run, whereas <code class="literal">bar</code> and <code class="literal">baz</code> are considered arguments to the program, which are passed on the commandline. <span class="emphasis"><em>Note</em></span>, that for windows-users, who tend to click on the icon (as opposed to starting <span class="application">yabasic</span> on the command line), this <code class="function">peek</code>will mostly return 0.</p><p>The function <code class="function">peek("argument")</code> can be written as <code class="function">peek("arguments")</code> too.</p><p>You will want to check out the corresponding function <code class="function"><a href="#ref_peek2" title="peek$">peek$("argument")</a></code> to actually <span class="emphasis"><em>retrieve</em></span> the arguments. <span class="emphasis"><em>Note</em></span>, that each call to <code class="function">peek$("argument")</code> reduces the number returned by <code class="function">peek("argument")</code>.</p></dd><dt><span class="term"><code class="function">peek("isbound")</code></span></dt><dd><p>Return <code class="constant">true</code>, if the executing <span class="application">yabasic</span>-program is part of a standalone program; see the section about <a href="#ref_standalone" title="Creating a standalone program from your yabasic-program">creating a <span class="emphasis"><em>standalone</em></span>-program</a> for details.</p></dd><dt><span class="term"><code class="function">peek("version")</code></span></dt><dd><p>Return the version number of yabasic (e.g. 2.72).</p></dd><dt><span class="term"><code class="function">peek("error")</code></span></dt><dd><p>Return a number specifying the nature of the last error in an <code class="function">open</code>- or <code class="function">seek</code>-statement. Normally an error within an <code class="function">open</code>-statement immediately terminates your program with an appropriate error-message, so there is no chance and no need to learn more about the nature of the error. However, if you use <code class="function">open</code> as a condition (e.g. <code class="literal">if (open(#1,"foo")) …</code>) the outcome (success or failure) of the <code class="function">open</code>-operation will determine, if the condition evaluates to <code class="constant">true</code> or <code class="constant">false</code>. If now such an operation fails, your program will not be terminated and you might want to learn the reason for failure. This reason will be returned by <code class="function">peek("error")</code> (as a number) or by <code class="function">peek$("error")</code> (as a string)</p><p>The table below shows the various error codes; the value returned by <code class="function">peek$("error")</code> explains the nature of the error. Note, that the codes 10,11 and 12 refer to the <code class="function">seek</code>-command.</p><div class="table"><a id="id2532734"></a><p class="title"><b>Table 6.1. Error codes</b></p><table summary="Error codes" border="1"><colgroup><col /><col /><col /></colgroup><thead><tr><th><code class="function">peek("error")</code></th><th><code class="function">peek$("error")</code></th><th>Explanation</th></tr></thead><tbody><tr><td align="center">2</td><td><code class="computeroutput">Stream already in use</code></td><td>Do not try to open one and the same filenumber twice; rather <code class="function"><a href="#ref_close" title="close">close</a></code> it first.</td></tr><tr><td align="center">3</td><td><code class="computeroutput">'x' is not a valid filemode</code></td><td>The optional <span class="emphasis"><em>filemode</em></span> argument, which may be passed to the <code class="function"><a href="#ref_open" title="open">open</a></code>-function, has an invalid value</td></tr><tr><td align="center">4</td><td><code class="computeroutput">could not open 'foo'</code></td><td>The <code class="function">open</code>-call did not work, no further explanation is available.</td></tr><tr><td align="center">5</td><td><code class="computeroutput">reached maximum number of open files</code></td><td>You have opened more files than your operating system permits.</td></tr><tr><td align="center">6</td><td><code class="computeroutput">cannot open printer: already printing graphics</code></td><td>The commands <code class="function"><a href="#ref_open_printer" title="open printer">open printer</a></code> and <code class="function"><a href="#ref_open" title="open">open #1,printer</a></code> both open a printer (refer to their description for the difference). However, only one can be active at a time; if you try to do both at the same time, you will receive this error.</td></tr><tr><td align="center">7</td><td><code class="computeroutput">could not open line printer</code></td><td>Well, it simply did not work.</td></tr><tr><td align="center">9</td><td><code class="computeroutput">invalid stream number</code></td><td>An attempt to use an invalid (e.g. negative) stream number; example: <code class="literal">open(-1,"foo")</code></td></tr><tr><td align="center">10</td><td><code class="computeroutput">could not position stream x to byte y</code></td><td><code class="function"><a href="#ref_seek" title="seek()">seek</a></code> did not work.</td></tr><tr><td align="center">11</td><td><code class="computeroutput">stream x not open</code></td><td>You have tried to <code class="function"><a href="#ref_seek" title="seek()">seek</a></code> within a stream, that has not been opened yet.</td></tr><tr><td align="center">12</td><td><code class="computeroutput">seek mode 'x' is none of begin,end,here</code></td><td>The argument, which has been passed to <code class="function"><a href="#ref_seek" title="seek()">seek</a></code> is invalid.</td></tr></tbody></table></div></dd></dl></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2533068"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open "foo" for reading as #1
open "bar" for writing as #2
while(not eof(#1))
  poke #2,chr$(peek(#1));
wend
          </pre><p>This program will copy the file <code class="filename">foo</code> byte by byte to <code class="filename">bar</code>.</p><p>Note, that each <code class="function">peek</code> does something entirely different, and only one has been demonstrated above. Therefore you need to make up examples yourself for all the other <code class="function">peek</code>s.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2533119"></a><h2>See also</h2><p><code class="function"><a href="#ref_peek2" title="peek$">peek$</a></code>, <code class="function"><a href="#ref_poke" title="poke">poke</a></code>, <code class="function"><a href="#ref_open" title="open">open</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_peek2"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>peek$ — retrieve various internal string-informations</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print peek$("foo")
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2533190"></a><h2>Description</h2><p>The <code class="function">peek$</code>-function has many different and unrelated uses. It is a kind of grabbag for retrieving all kinds of string information, internal to <span class="application">yabasic</span>; the exact nature of the strings returned be the <code class="function">peek$</code>-function depends on the string passed as an argument.</p><p><code class="function">peek$</code> always returns a string, however the closely related <code class="function"><a href="#ref_peek" title="peek">peek</a></code>-function exists, which may be used to retrieve numerical information from among the internals of <span class="application">yabasic</span>. Finally note, that some of the values which are retrieved with <code class="function">peek$</code> may even be changed, using the <code class="function"><a href="#ref_poke" title="poke">poke</a></code>-function.</p><p>The following list shows all possible arguments to <code class="function">peek$</code>:</p><div class="variablelist"><dl><dt><span class="term"><code class="function">peek$("infolevel")</code></span></dt><dd><p>Returns either <code class="literal">"debug"</code>, <code class="literal">"note"</code>, <code class="literal">"warning"</code>, <code class="literal">"error"</code> or <code class="literal">"fatal"</code>, depending on the current infolevel. This value can be specified with an option (either under <a href="#windows_options">windows</a> or <a href="#unix_options">unix</a>) on the commandline or changed during the execution of the program with the corresponding <code class="function"><a href="#ref_poke" title="poke">poke</a></code>; however, normally only the author of <span class="application">yabasic</span> (<span class="emphasis"><em>me</em></span> !) would want to change this from its default value <code class="literal">"warning"</code>.</p></dd><dt><span class="term"><code class="function">peek$("textalign")</code></span></dt><dd><p>Returns one of nine possible strings, specifying the default alignment of text within the graphics-window. The alignment-string returned by this <code class="function">peek</code> describes, how the <code class="function"><a href="#ref_text" title="text">text</a></code>-command aligns its string-argument with respect to the coordinates supplied. However, this value does <span class="emphasis"><em>not apply</em></span>, if the <code class="function">text</code>-command explicitly specifies an alignment. Each of these strings is two characters long. The first character specifies the horizontal alignment and can be either <code class="literal">l</code>, <code class="literal">r</code> or <code class="literal">c</code>, which stand for <em class="wordasword">left</em>, <em class="wordasword">right</em> or <em class="wordasword">center</em>. The second character specifies the vertical alignment and can be one of <code class="literal">t</code>, <code class="literal">b</code> or <code class="literal">c</code>, which stand for <em class="wordasword">top</em>, <em class="wordasword">bottom</em> or <em class="wordasword">center</em> respectively.</p><p>You may change this value with the corresponding command <code class="function">poke "textalign",…</code>; the initial value is <code class="literal">lb</code>, which means the top of the left and the top edge if the text will be aligned with the coordinates, that are specified within the <code class="function">text</code>-command.</p></dd><dt><span class="term"><code class="function">peek$("windoworigin")</code></span></dt><dd><p>This <code class="function">peek</code> returns a two character string, which specifies the position of the origin of the coordinate system of the window; this string might be changed with the corresponding command <code class="function">poke "windoworigin",x,y</code> or specified as the argument of the <code class="function"><a href="#ref_origin" title="window origin">origin</a></code> command; see there for a detailed description of the string, which might be returned by this <code class="function">peek</code>.</p></dd><dt><span class="term"><code class="function">peek$("error")</code></span></dt><dd><p>Return a string describing the nature of the last error in an <code class="function">open</code>- or <code class="function">seek</code>-statement. See the corresponding <code class="function"><a href="#ref_peek" title="peek">peek("error")</a></code> for a detailed description.</p></dd><dt><span class="term"><code class="function">peek$("library")</code></span></dt><dd><p>Return the name of the library, this statement is contained in. See the <code class="function"><a href="#ref_import" title="import">import</a></code>-command for a detailed description or for more about libraries.</p></dd><dt><span class="term"><code class="function">peek$("os")</code></span></dt><dd><p>This <code class="function">peek</code> returns the name of the operating system, where your program executes. This can be either <code class="literal">windows</code> or <code class="literal">unix</code>.</p></dd><dt><span class="term"><code class="function">peek$("font")</code></span></dt><dd><p>Return the name of the font, which is used for text within the graphic window; this value can be specified as the third argument to the <code class="function"><a href="#ref_open_window" title="open window">open window</a></code>-command.</p></dd><dt><span class="term"><code class="function">peek$("env","<em class="replaceable"><code>NAME</code></em>")</code></span></dt><dd><p>Return the environment variable specified by <em class="replaceable"><code>NAME</code></em> (which may be any string expression). Which kind of environment variables are available on your system depends, as well as their meaning, on your system; however typing <span><strong class="command">env</strong></span> on the commandline will produce a list (for Windows and Unix alike). Note, that <code class="function">peek$("env",...)</code> can be written as <code class="function">peek$("environment",...)</code> too.</p></dd><dt><span class="term"><code class="function">peek$("argument")</code></span></dt><dd><p>Return one of the arguments, that have been passed to <span class="application">yabasic</span> at invocation time (the next call will return the the second argument, and so on). E.g. if <span class="application">yabasic</span> has been called like this: <code class="literal">yabasic foo.yab bar baz</code>, then the first call to <code class="function">peek$("argument")</code> will return <code class="literal">bar</code>. This is because <code class="literal">foo.yab</code> is treated as the name of the program to run, whereas <code class="literal">bar</code> and <code class="literal">baz</code> are considered arguments to this program, which are passed on the commandline. The second call to <code class="function">peek$("argument")</code> will return <code class="literal">baz</code>. <span class="emphasis"><em>Note</em></span>, that for windows-users, who tend to click on the icon (as opposed to starting <span class="application">yabasic</span> on the command line), this <code class="function">peek</code>will mostly return the empty string.</p><p>Note, that <code class="function">peek$("argument")</code> can be written as <code class="function">peek$("arguments")</code>.</p><p>Finally you will want to check out the corresponding function <code class="function"><a href="#ref_peek" title="peek">peek("argument")</a></code>.</p></dd></dl></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2533863"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "You have supplied these arguments: "
while(peek("argument"))
  print peek("argument"),peek$("argument")
wend
          </pre><p>If you save this program in a file <code class="filename">foo.yab</code> and execute it via <strong class="userinput"><code>yabasic t.yab a b c</code></strong> (for windows users: please use the commandline for this), your will get this output:</p><pre class="screen">
3a
2b
1c
</pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2533904"></a><h2>See also</h2><p><code class="function"><a href="#ref_peek" title="peek">peek</a></code>, <code class="function"><a href="#ref_poke" title="poke">poke</a></code>, <code class="function"><a href="#ref_open" title="open">open</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_pi"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>pi — a constant with the value <code class="computeroutput">3.14159</code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print pi
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2533979"></a><h2>Description</h2><p><code class="function">pi</code> is <code class="literal">3.14159265359</code> (well at least for <span class="application">yabasic</span>); do not try to assign to pi (e.g. <code class="literal">pi=22/7</code>) this would not only be mathematically dubious, but would also result in a syntax error.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2534013"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=0 to 180
  print "The sine of ",a," degrees is ",sin(a*pi/180)
next a
          </pre><p>This program uses <code class="function">pi</code> to transform an angle from degrees into radians.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2534040"></a><h2>See also</h2><p><code class="function"><a href="#ref_euler" title="euler">euler</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_poke"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>poke — change selected internals of <span class="application">yabasic</span></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
poke "foo","bar"
poke "foo",baz
poke #a,"bar"
poke #a,baz
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2534096"></a><h2>Description</h2><p>The <code class="function">poke</code>-command may be used to change details of <span class="application">yabasic</span>'s behaviour. Like the related function <code class="function">peek</code>, <code class="function">poke</code> does many different things, depending on the arguments supplied.</p><p>Here are the different things you can do with <code class="function">poke</code>:</p><div class="variablelist"><dl><dt><span class="term"><code class="function">poke "textalign","cc"</code></span></dt><dd><p>This <code class="function">poke</code> changes the <span class="emphasis"><em>default</em></span> alignment of text with respect to the coordinates supplied within the <code class="function">text</code>-command. However, this value does <span class="emphasis"><em>not apply</em></span>, if the <code class="function">text</code>-command explicitly specifies an alignment. The second argument (<code class="literal">"cc"</code> in the example) must always be two characters long; the first character can be one of <code class="literal">l</code> (<em class="wordasword">left</em>), <code class="literal">r</code> (<em class="wordasword">right</em>) or <code class="literal">c</code> (<em class="wordasword">center</em>); the second character can be either <code class="literal">t</code> (<em class="wordasword">top</em>), <code class="literal">b</code> (<em class="wordasword">bottom</em>) or <code class="literal">c</code> (<em class="wordasword">center</em>); see the corresponding <code class="function"><a href="#ref_peek2" title="peek$">peek$("textalign")</a></code> for a detailed description of this argument.</p></dd><dt><span class="term"><code class="function">poke "windoworigin","lt"</code></span></dt><dd><p>This <code class="function">poke</code> moves the origin of the coordinate system of the window to the specified position. The second argument (<code class="literal">"lt"</code> in the example) must always be two characters long; the first character can be one of <code class="literal">l</code> (<em class="wordasword">left</em>), <code class="literal">r</code> (<em class="wordasword">right</em>) or <code class="literal">c</code> (<em class="wordasword">center</em>); the second character can be either <code class="literal">t</code> (<em class="wordasword">top</em>), <code class="literal">b</code> (<em class="wordasword">bottom</em>) or <code class="literal">c</code> (<em class="wordasword">center</em>). Together those two characters specify the new position of the coordinate-origin. See the corresponding <code class="function"><a href="#ref_peek2" title="peek$">peek$("windoworigin")</a></code> for a more in depth description of this argument.</p></dd><dt><span class="term"><code class="function">poke "infolevel","debug"</code></span></dt><dd><p>Change the amount of internal information, that <span class="application">yabasic</span> outputs during execution.</p><p>The second argument can be either <code class="literal">"debug"</code>, <code class="literal">"note"</code>, <code class="literal">"warning"</code>, <code class="literal">"error"</code> or <code class="literal">"fatal"</code>. However, normally you will not want to change this from its default value <code class="literal">"warning"</code>.</p><p>See also the related <code class="function"><a href="#ref_peek2" title="peek$">peek$("infolevel")</a></code>.</p></dd><dt><span class="term"><code class="function">poke #1,a</code></span></dt><dd><p>Write the given byte (<code class="literal">a</code> in the example above) to the specified stream (<code class="literal">#a</code> in the example).</p><p>See also the related function function <code class="function"><a href="#ref_peek" title="peek">peek(#1)</a></code>.</p></dd></dl></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2534484"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "Hello, now you will see, how much work"
print "a simple for-loop involves ..."
input "Please press return " a$
poke "infolevel","debug"
for a=1 to 10:next a
          </pre><p>This example only demonstrates one of the many <code class="function">poke</code>s, which are described above: The program switches the infolevel to <code class="literal">debug</code>, which makes <span class="application">yabasic</span> produce a lot of debug-messages during the subsequent <code class="function">for</code>-loop.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2534533"></a><h2>See also</h2><p><code class="function"><a href="#ref_peek" title="peek">peek</a></code>, <code class="function"><a href="#ref_peek2" title="peek$">peek$</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_print"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>print — Write to terminal or file</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print "foo",a$,b
print "foo","a$,b;
print #a "foo",a$
print #a "foo",a$;
print foo using "##.###"
print reverse "foo"
print at(10,10) a$,b
print @(10,10) a$,b
print color("red","blue") a$,b
print color("magenta") a$,b
print color("green","yellow") at(5,5) a$,b
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2534598"></a><h2>Description</h2><p>The <code class="function">print</code>-statement outputs strings or characters, either to your terminal (also known as <em class="wordasword">console</em>) or to an open file.</p><p>To understand all those uses of the <code class="function">print</code>-statement, let's go through the various lines in the synopsis above:</p><div class="variablelist"><dl><dt><span class="term"><code class="literal">print "foo",a$,b</code></span></dt><dd><p>Print the string <code class="literal">foo</code> as well as the contents of the variables <code class="literal">a$</code> and <code class="literal">b</code> onto the screen, silently adding a <span class="emphasis"><em>newline</em></span>.</p></dd><dt><span class="term"><code class="literal">print "foo",a$,b;</code></span></dt><dd><p>(Note the trailing semicolon !) This statement does the same as the one above; only the implicit <span class="emphasis"><em>newline</em></span> is skipped, which means that the next <code class="function">print</code>-statement will append seamlessly.</p></dd><dt><span class="term"><code class="literal">print #a "foo",a$</code></span></dt><dd><p>This is the way to write to files. The file with the number <code class="literal">a</code> must be open already, an implicit <span class="emphasis"><em>newline</em></span> is added. Note the file-number <code class="literal">#a</code>, which starts with a hash ('<code class="literal">#</code>') amd is separated from the rest of the statement by a space only. The file-number (contained in the variable <code class="literal">a</code>) must have been returned by a previous <code class="function"><a href="#ref_open" title="open">open</a></code>-statement (e.g. <code class="literal">a=open("bar")</code>).</p></dd><dt><span class="term"><code class="literal">print #a "foo",a$;</code></span></dt><dd><p>The same as above, but without the implicit <span class="emphasis"><em>newline</em></span>.</p></dd><dt><span class="term"><code class="literal">print foo using "##.###"</code></span></dt><dd><p>Print the number <code class="varname">foo</code> with as many digits before and after the decimal dot as given by the number of '<code class="literal">#</code>'-signs. See the entries for <code class="function"><a href="#ref_using" title="using">using</a></code> and <code class="function"><a href="#ref_str" title="str$()">str$</a></code> for a detailed description of this format.</p></dd><dt><span class="term"><code class="literal">print reverse "foo"</code></span></dt><dd><p>As all the <code class="function">print</code>-variants to follow, this form of the <code class="function">print</code>-statement can only be issued after <code class="function"><a href="#ref_clear_screen" title="clear screen">clear screen</a></code> has been called. The strings and numbers after the <code class="literal">reverse</code>-clause are simply printed inverse (compared to the normal <code class="function">print</code>-statement).</p></dd><dt><span class="term"><code class="literal">print at(10,10) a$,b</code></span></dt><dd><p>Print at the specified (x,y)-position. This is only allowed after <code class="function">clear screen</code> has been called. You may want to query <code class="function"><a href="#ref_peek2" title="peek$">peek$("screenwidth")</a></code> or <code class="function"><a href="#ref_peek2" title="peek$">peek$("screenheight")</a></code> to learn the actual size of your screen. You may add a semicolon to suppress the implicit newline.</p></dd><dt><span class="term"><code class="literal">print @(10,10) a$,b</code></span></dt><dd><p>This is exactly the same as above, however, <code class="literal">at</code> may be written as <code class="literal">@</code>.</p></dd><dt><span class="term"><code class="literal">print color("red","blue") at(5,5) a$,b</code></span></dt><dd><p>Print with the specified fore- (<code class="literal">"red"</code>) and background (<code class="literal">"blue"</code>) color (or colour). The possible values are <code class="literal">"black"</code>, <code class="literal">"white"</code>, <code class="literal">"red"</code>, <code class="literal">"blue"</code>, <code class="literal">"green"</code>, <code class="literal">"yellow"</code>, <code class="literal">"cyan"</code> or <code class="literal">"magenta"</code>. Again, you need to call <code class="literal">clear screen</code> first and add a semicolon if you want to suppress the implicit newline.</p></dd><dt><span class="term"><code class="literal">print color("magenta") a$,b</code></span></dt><dd><p>You may specify the foreground color only.</p></dd><dt><span class="term"><code class="literal">print color("green","yellow") a$,b</code></span></dt><dd><p>A color and a position (in this sequence, not the other way around) may be specified at once.</p></dd></dl></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2535086"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
columns=peek("screenwidth")
lines=peek("screenheight")
dim col$(7)
for a=0 to 7:read col$(a):next a
data "black","white","red","blue","green","yellow","cyan","magenta"

for a=0 to 2*pi step 0.1
  print colour(col$(mod(i,8))) at(columns*(0.8*sin(a)+0.9)/2,lines*(0.8*cos(a)+0.9)/2) "*"
  i=i+1
next a
          </pre><p>This example draws a colored ellipse within the text window.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2535111"></a><h2>See also</h2><p><code class="function"><a href="#ref_at" title="at()">at</a></code><code class="function">, <code class="function"><a href="#ref_print_color" title="print color">print color</a></code>, <a href="#ref_input" title="input">input</a></code>, <code class="function"><a href="#ref_clear_screen" title="clear screen">clear screen</a></code>, <code class="function"><a href="#ref_using" title="using">using</a></code>, <code class="function"><a href="#ref_semicolon" title=";">;</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_print_color"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>print color — print with color</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print color(fore$) text$
print color(fore$,back$) text$
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2535214"></a><h2>Description</h2><p>Not a separate command, but part of the <code class="function">print</code>-command; may be included just after <code class="function">print</code> and can only be issued after <code class="function">clear screen</code> has been executed.</p><p><code class="function">color()</code> takes one or two string-arguments, specifying the color of the text and (optionally) the background.</p><p>The one or two strings passed to <code class="function">color()</code> can be one of these: <code class="systemitem">"black"</code>, <code class="systemitem">"white"</code>, <code class="systemitem">"red"</code>, <code class="systemitem">"blue"</code>, <code class="systemitem">"green"</code>, <code class="systemitem">"yellow"</code>, <code class="systemitem">"cyan"</code> and <code class="systemitem">"magenta"</code> (which can be abbreviated as <code class="systemitem">"bla"</code>, <code class="systemitem">"whi"</code>, <code class="systemitem">"red"</code>, <code class="systemitem">"blu"</code>, <code class="systemitem">"gre"</code>, <code class="systemitem">"yel"</code>, <code class="systemitem">"cya"</code> and <code class="systemitem">"mag"</code> respectively).</p><p><code class="function">color()</code> can only be used, if <code class="function"><a href="#ref_clear_screen" title="clear screen">clear scren</a></code> has been issued at least once.</p><p>Note, that <code class="function">color()</code> can be written as <code class="function">colour()</code> too.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2535392"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
dim col$(7):for a=0 to 7:read col$(a):next a
do
  print color(col$(ran(7)),col$(ran(7))) " Hallo ";
  pause 0.01
loop
data "black","white","red","blue"
data "green","yellow","cyan","magenta"
          </pre><p>This prints the word <code class="systemitem">" Hallo "</code> in all colors across your screen.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2535421"></a><h2>See also</h2><p><code class="function"><a href="#ref_print" title="print">print</a></code>, <code class="function"><a href="#ref_clear_screen" title="clear screen">clear screen</a></code>, <code class="function"><a href="#ref_at" title="at()">at</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_print_colour"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>print colour — see <code class="function"><a href="#ref_print_color" title="print color">color</a></code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print colour(fore$) text$
print colour(fore$,back$) text$
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2535502"></a><h2>See also</h2><p><code class="function"><a href="#ref_print_color" title="print color">color</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_putbit"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>putbit — draw a rectangle of pixels encoded within a string into the graphics window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open window 200,200
…
a$=getbit(20,20,50,50)
…
putbit a$,30,30
putbit a$ to 30,30
putbit a$,30,30,"or"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2535556"></a><h2>Description</h2><p>The <code class="function">putbit</code>-command is the counterpart of the <code class="function"><a href="#ref_getbit" title="getbit$()">getbit</a></code>-function. <code class="function">putbit</code> requires a string as returned by the <code class="function"><a href="#ref_getbit" title="getbit$()">getbit</a></code>-function. Such a string contains a rectangle from the graphic window; the <code class="function">putbit</code>-function puts such a rectangular region back into the graphic-window.</p><p>Note, that the <code class="function">putbit</code>-command currently accepts a third argument. However only the string value <code class="literal">"or"</code> is supported here. The effect is, that only those pixel, which are set in the string will be set in the graphic window. Those pixels, which are not set in the string, will not change in the window (as opposed to being cleared).</p><p>Note, that the format of the string returned by this function is due to change as soon as <span class="application">yabasic</span> will learn, how to deal with colors.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2535639"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">

c$="rgb 21,21:0000000000000000000000000000000000000000000000000000000000000032c80000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c8c8ff000032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000032c80032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80032c80000000000000000000032c80032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80000000000000032c80032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80032c80000000000000000000032c80032c80032c80032c80032c8c8ff00c8ff00c8ff00c8ff00c8ff00c8ff00c8ff000032c80032c80032c80032c80032c80000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80032c80000000000000000000000000000000000000000000000000000000000000000000032c80032c80032c80032c80032c80032c80032c80032c80032c8000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"

open window 200,200

do
  x=ran(220)-10
  y=ran(220)-10
  putbit c$,x,y,"transparent"
loop
          </pre><p>This program uses a precanned string (containing the image of a blue circle with a yellow centre) and draws it repeatedly into the graphic-window. The mode <code class="literal">"transparent"</code> ensures, that no pixels will be cleared.</p></div><p>There are two possible values for the third argument of <code class="function">putbit</code>. Both modes differ in the way, they replace (or not) any pixels from the window with pixels from the bitmap having the background colour.</p><div class="variablelist"><dl><dt><span class="term"><code class="literal">transparent</code> or <code class="literal">t</code></span></dt><dd><p>With this mode the pixels from the window will be kept, if the bitmap contains pixels with background colour at this position; i.e. the bitmap is <span class="emphasis"><em>transparent</em></span></p></dd><dt><span class="term"><code class="literal">solid</code> or <code class="literal">s</code></span></dt><dd><p>With this mode the pixels from the window will be overpainted with the pixels from the bitmap in any case; i.e. the bitmap is <span class="emphasis"><em>solid</em></span></p></dd></dl></div><p>If you omit this argument, the default <code class="literal">transparent</code> applies.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2535792"></a><h2>See also</h2><p><code class="function"><a href="#ref_getbit" title="getbit$()">getbit$</a></code>, <code class="function"><a href="#ref_open_window" title="open window">open window</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_putscreen"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>putscreen — draw a rectangle of characters into the text terminal</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
…
a$=getscreen$(5,5,10,10)
…
putscreen a$,7,7
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2535856"></a><h2>Description</h2><p>The <code class="function">putscreen</code>-command is the counterpart of the <code class="function"><a href="#ref_getscreen" title="getscreen$()">getscreen$</a></code>-function. <code class="function">putscreen</code> requires a string as returned by the <code class="function"><a href="#ref_getscreen" title="getscreen$()">getscreen</a></code>-function. Such a string contains a rectangular detail from the terminal; the <code class="function">putscreen</code>-function puts such a region back into the terminal-window.</p><p>Note, that <code class="function"><a href="#ref_clear_screen" title="clear screen">clear screen</a></code> must have been called before.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2535922"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
for a=1 to 200
  print color("red") "Hallo !"; 
  print color("blue") "Welt !";
next a
r$=getscreen$(0,0,20,20)
for x=0 to 60
  putscreen r$,x,0
  sleep 0.1
next x
          </pre><p>This example prints the string <code class="literal">"Hallo !Welt !"</code> all over the screen and then moves a rectangle from one side to the other.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2535952"></a><h2>See also</h2><p><code class="function"><a href="#ref_getscreen" title="getscreen$()">getscreen$</a></code>, <code class="function"><a href="#ref_clear_screen" title="clear screen">clear screen</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_r"></a>R</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_ran">ran()</a></span><span class="refpurpose"> - return a random number</span></dt><dt><span class="refentrytitle"><a href="#ref_read">read</a></span><span class="refpurpose"> - read data from data-statements</span></dt><dt><span class="refentrytitle"><a href="#ref_rectangle">rectangle</a></span><span class="refpurpose"> - draw a rectangle</span></dt><dt><span class="refentrytitle"><a href="#ref_redim">redim</a></span><span class="refpurpose"> - create an array prior to its first use. A synonym for dim</span></dt><dt><span class="refentrytitle"><a href="#ref_rem">rem</a></span><span class="refpurpose"> - start a comment</span></dt><dt><span class="refentrytitle"><a href="#ref_repeat">repeat</a></span><span class="refpurpose"> - start a repeat-loop</span></dt><dt><span class="refentrytitle"><a href="#ref_restore">restore</a></span><span class="refpurpose"> - reposition the data-pointer</span></dt><dt><span class="refentrytitle"><a href="#ref_return">return</a></span><span class="refpurpose"> - return from a subroutine or a gosub</span></dt><dt><span class="refentrytitle"><a href="#ref_reverse">reverse</a></span><span class="refpurpose"> - print reverse (background and foreground colors exchanged)</span></dt><dt><span class="refentrytitle"><a href="#ref_right">right$()</a></span><span class="refpurpose"> - return (or change) the right end of a string</span></dt><dt><span class="refentrytitle"><a href="#ref_rinstr">rinstr()</a></span><span class="refpurpose"> - find the rightmost occurrence of one string within the other</span></dt><dt><span class="refentrytitle"><a href="#ref_rtrim">rtrim$()</a></span><span class="refpurpose"> - trim spaces at the right end of a string</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_ran"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>ran() — return a random number</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print ran()
x=ran(y)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536025"></a><h2>Description</h2><p>The <code class="function">ran</code>-function returns a random number. If no argument is given, the number returned is in the range from 0 to 1; where only 0 is a possible value; 1 will never be returned. If an argument is supplied, the number returned will be in the range from 0 up to this argument, whereas this argument itself is not a possible return value.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536046"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
c=peek("screenwidth")-1
l=peek("screenheight")

dim col$(8)
for a=0 to 7:read col$(a):next a
data "black","white","red","blue","green","yellow","cyan","magenta"

do
  x=ran(c)
  y=l-ran(l*exp(-32*((x/c-1/2)**2)))
  i=i+1
  print color(col$(mod(i,8))) at(x,y) "*";
loop
          </pre><p>This example will print a cloured bell-curve.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536071"></a><h2>See also</h2><p><code class="function"><a href="#ref_int" title="int()">int</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_read"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>read — read data from <code class="function">data</code>-statements</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
read a$,a
…
data "Hello !",7
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536128"></a><h2>Description</h2><p>The <code class="function">read</code>-statement retrieves literal data, which is stored within <code class="function">data</code>-statements elsewhere in your program.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536151"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
read num
dim col$(num)
for a=1 to num:read col$(a):next a
clear screen
print "These are the colours known to yabasic:\n"
for a=1 to num
  print colour(col$(a)) col$(a)
next a

data 8,"black","white","red","blue"
data "green","yellow","cyan","magenta"
          </pre><p>This program prints the names of the colors known to <span class="application">yabasic</span> in those very colors.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536182"></a><h2>See also</h2><p><code class="function"><a href="#ref_data" title="data">data</a>, <code class="function"><a href="#ref_restore" title="restore">restore</a></code></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_rectangle"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>rectangle — draw a rectangle</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open window 100,100
rectangle 10,10 to 90,90
rectangle 20,20,80,80
rect 20,20,80,80
box 30,30,70,70
clear rectangle 30,30,70,70
fill rectangle 40,40,60,60
clear fill rectangle 60,60,40,40
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536245"></a><h2>Description</h2><p>The <code class="function">rectangle</code>-command (also known as <code class="function">box</code> or <code class="function">rect</code>, for short) draws a rectangle; it accepts four parameters: The x- and y-coordinates of two facing cornerpoints of the rectangle. With the optional clauses <code class="function">clear</code> and <code class="function">fill</code> (which may appear both and in any sequence) the rectangle can be cleared and filled respectively.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536289"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
c=1
do 
  for phi=0 to pi step 0.1
    if (c) then 
      rectangle 100+100*sin(phi),100+100*cos(phi) to 100-100*sin(phi),100-100*cos(phi)
    else 
      clear rectangle 100+100*sin(phi),100+100*cos(phi) to 100-100*sin(phi),100-100*cos(phi)
    endif
    sleep 0.1
  next phi
  c=not c
loop
          </pre><p>This example draws a nice animated pattern; watch it for a couple of hours, to see how it develops.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536315"></a><h2>See also</h2><p><code class="function"><a href="#ref_open_window" title="open window">open window</a></code>, <code class="function"><a href="#ref_open_printer" title="open printer">open printer</a></code>, <code class="function"><a href="#ref_line" title="line">line</a></code>, <code class="function"><a href="#ref_circle" title="circle">circle</a></code>, <code class="function"><a href="#ref_triangle" title="triangle">triangle</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_redim"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>redim — create an array prior to its first use. A synonym for <code class="function">dim</code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
See the <code class="function"><a href="#ref_dim" title="dim">dim</a></code>-command.
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536422"></a><h2>Description</h2><p>The <code class="function">redim</code>-command does exactly the same as the <code class="function"><a href="#ref_dim" title="dim">dim</a></code>-command; it is just a <span class="emphasis"><em>synonym</em></span>. <code class="function">redim</code> has been around in older versions of <span class="acronym">basic</span> (not even <span class="application">yabasic</span>) for many years; therefore it is supported in <span class="application">yabasic</span> for compatibility reasons.</p><p>Please refer to the entry for the <code class="function"><a href="#ref_dim" title="dim">dim</a></code>-command for further information.</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_rem"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>rem — start a comment</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
rem  Hey, this is a comment
#    this is a comment too
// even this
print "Not a comment" #    This is an error !!
print "Not a comment"://   But this is again a valid comment
print "Not a comment" //   even this.
print "Not a comment" rem  and this !
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536526"></a><h2>Description</h2><p><code class="function">rem</code> introduces a comment (like <code class="literal">#</code> or <code class="literal">//</code>), that extends up to the end of the line.</p><p>Those comments do not even need a colon
('<code class="literal">:</code>') in front of them; they (<code class="literal">rem</code>, <code class="literal">#</code> and <code class="literal">//</code>) all behave alike except for <code class="literal">#</code>, which may only appear at the very beginning of a line; therefore the fourth example in the synopsis above (<code class="literal">print "Not a comment" #    This is an error !!</code>) is indeed an error.</p><p>Note, that <code class="function">rem</code> is an abbreviation for <span class="emphasis"><em>remark</em></span>. <code class="function">remark</code> however is <span class="emphasis"><em>not</em></span> a valid command in <span class="application">yabasic</span>.</p><p>Finally note, that a comment introduced with '<code class="literal">#</code>' may have a special meaning under unix; see the entry for <a href="#ref_hash" title="#">#</a> for details.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536641"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
#
rem   comments on data structures
#     are more useful than
//    comments on algorithms.
rem
          </pre><p>This program does nothing, but in a splendid and well commented way.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536663"></a><h2>See also</h2><p><code class="function"><a href="#ref_hash" title="#">#</a></code>, <code class="function"><a href="#ref_double_slash" title="//">//</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_repeat"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>repeat — start a <code class="function">repeat</code>-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
repeat 
  …
until (…)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536730"></a><h2>Description</h2><p>The <code class="function">repeat</code>-loop executes all the statements up to the final <code class="function">until</code>-keyword over and over. The loop is executed as long as the condition, which is specified with the <code class="function">until</code>-clause, becomes true. By construction, the statements within the loop are executed at least once.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536761"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
x=0
clear screen
print "This program will print the numbers from 1 to 10"
repeat
  x=x+1
  print x
  print "Press any key for the next number, or 'q' to quit"
  if (inkey$="q") break
until(x=10)
          </pre><p>This program is pretty much useless, but self-explanatory.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536784"></a><h2>See also</h2><p><code class="function"><a href="#ref_until" title="until">until</a></code>, <code class="function"><a href="#ref_break" title="break">break</a></code>, <code class="function"><a href="#ref_while" title="while">while</a></code>, <code class="function"><a href="#ref_do" title="do">do</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_restore"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>restore — reposition the <code class="function">data</code>-pointer</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
read a,b,c,d,e,f
restore
read g,h,i
restore foo
data 1,2,3
label foo
data 4,5,6
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536872"></a><h2>Description</h2><p>The <code class="function">restore</code>-command may be used to <span class="emphasis"><em>reset</em></span> the reading of <code class="function">data</code>-statements, so that the next <code class="function">read</code>-statement will read data from the first <code class="function">data</code>-statement.</p><p>You may specify a <a href="#ref_label" title="label">label</a> with the <code class="function">restore</code>-command; in that case, the next <code class="function">read</code>-statement will read data starting at the given label. If the label is omitted, reading data will begin with the first <code class="function">data</code>-statement within your program.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536943"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Which language (german/english) ? " l$
if (instr("german",l$)&gt;0) then
  restore german
else
  restore english
endif

for a=1 to 3
  read x,x$
  print x,"=",x$
next a

label english
data 1,"one",2,"two",3,"three"
label german
data 1,"eins",2,"zwei",3,"drei"
          </pre><p>This program asks to select one of those languages known to me (i.e. english or german) and then prints the numbers 1,2 and 3 and their textual equivalents in the chosen language.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2536969"></a><h2>See also</h2><p><code class="function"><a href="#ref_read" title="read">read</a></code>, <code class="function"><a href="#ref_data" title="data">data</a></code>, <code class="function"><a href="#ref_label" title="label">label</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_return"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>return — return from a subroutine or a gosub</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
gosub foo
…
label foo
…
return

sub bar(baz)
  …
  return quertz
end sub
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537042"></a><h2>Description</h2><p>The <code class="function">return</code>-statement serves two different (albeit somewhat related) purposes. The probably more important use of <code class="function">return</code> is to return control from within a subroutine to the place in your program, where the subroutine has been called. If the subroutine is declared to return a value, the <code class="function">return</code>-statement might be accompanied by a string or number, which constitutes the <span class="emphasis"><em>return value</em></span> of the subroutine.</p><p>However, even if the subroutine should return a value, the <code class="function">return</code>-statement need not carry a value; in that case the subroutine will return 0 or the empty string (depending on the type of the subroutine). Moreover, feel free to place multiple <code class="function">return</code>-statements within your subroutine; it's a nice way of controlling the flow of execution.</p><p>The second (but historicially first) use of <code class="function">return</code> is to return to the position, where a prior <code class="function"><a href="#ref_gosub" title="gosub">gosub</a></code> has left off. In that case <code class="function">return</code> may <span class="emphasis"><em>not</em></span> carry a value.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537130"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
do
  read a$
  if (a$="") then
    print
    end
  endif
  print mark$(a$)," ";
loop

data "The","quick","brown","fox","jumped"
data "over","the","lazy","dog",""

sub mark$(a$)
  if (instr(lower$(a$),"q")) return upper$(a$)
  return a$
end sub
          </pre><p>This example features a subroutine <code class="function">mark$</code>, that returns its argument in upper case, if it contains the letter "q", or unchanged otherwise. In the test-text the word <code class="literal">quick</code> will end up being marked as <code class="literal">QUICK</code>.</p><p>The example above demonstrates <code class="function">return</code> within subroutines; please see <a href="#ref_gosub" title="gosub"><code class="function">gosub</code></a> for an example of how to use <code class="function">return</code> in this context.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537201"></a><h2>See also</h2><p><a href="#ref_sub" title="sub"><code class="function">sub</code></a>, <a href="#ref_gosub" title="gosub"><code class="function">gosub</code></a></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_reverse"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>reverse — print reverse (background and foreground colors exchanged)</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
…
print reverse "foo"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537263"></a><h2>Description</h2><p><code class="function">reverse</code> may be used to <code class="function">print</code> text in reverse. <code class="function">reverse</code> is not a separate command, but part of the <code class="function">print</code>-command; it may be included just after the <code class="function">print</code> and can only be issued once that <code class="function">clear screen</code> has been issued.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537310"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen

print "1 ";
c=3
do
  prim=true
  for a=2 to sqrt(c)
    if (frac(c/a)=0) then
      prim=false
      break
    endif
  next a
  if (prim) then
    print
    print reverse c;
  else
    print c;
  endif
  print " ";
  c=c+1
loop
          </pre><p>This program prints numbers from 1 on and marks each prime number in reverse.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537334"></a><h2>See also</h2><p><code class="function"><a href="#ref_at" title="at()">at</a></code><code class="function">, <code class="function"><a href="#ref_print_color" title="print color">print color</a></code>, <a href="#ref_print" title="print">print</a></code>, <code class="function"><a href="#ref_clear_screen" title="clear screen">clear screen</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_right"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>right$() — return (<span class="emphasis"><em>or change</em></span>) the right end of a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print right$(a$,2)
right$(b$,2)="baz"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537419"></a><h2>Description</h2><p>The <code class="function">right$</code>-function requires two arguments (a string and a number) and returns the part from the right end of the string, whose length is specified by its second argument. So, <code class="function">right$</code> simply returns the requested number of chars from the right end of the given string.</p><p>Note, that the <code class="function">right$</code>-function can be assigned to, i.e. it may appear on the left hand side of an assignment. In this way it is possible to change a part of the variable used within the <code class="function">right$</code>-function. Note, that that way the <span class="emphasis"><em>length</em></span> of the string cannot be changed, i.e. characters might be overwritten, but not added. For an example see below.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537469"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "Please enter a length either in inch or centimeter"
print "please add 'in' or 'cm' to mark the unit."
input "Length: " a$
if (right$(a$,2)="in") then
   length=val(a$)*2.56
elsif (right$(a$,2)="cm") then
   length=val(a$)
else
   error "Invalid input: "+a$
endif
          </pre><p>This program allows the user to enter a length qualified with a unit (either inch or centimeter).</p><p>This second example demonstrates the capability to <span class="emphasis"><em>assign</em></span> to the <code class="function">right$</code>-function.</p><pre class="programlisting">
a$="Heiho World !"
print a$
right$(a$,7)="dwarfs."
print a$
</pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537515"></a><h2>See also</h2><p><code class="function"><a href="#ref_right" title="right$()">right$</a></code> and <code class="function"><a href="#ref_mid" title="mid$()">mid$</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_rinstr"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>rinstr() — find the rightmost occurrence of one string within the other</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
pos=rinstr("Thequickbrownfox","equi")
pos=rinstr(a$,b$,x)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537578"></a><h2>Description</h2><p>The <code class="function">rinstr</code>-function accepts two string-arguments and tries to find the second within the first. However, unlike the <code class="function"><a href="#ref_instr" title="instr()">instr</a></code>, the <code class="function">rinstr</code>-function finds the <span class="emphasis"><em>rightmost</em></span> (or last) occurrence of the string; whereas the <code class="function">instr</code>-function finds the <span class="emphasis"><em>leftmost</em></span> (or first) occurrence. In any case however, the position is counted from the left.</p><p>If you supply a third, numeric argument to the <code class="function">rinstr</code>-function, it will be used as a starting point for the search. Therefore <code class="function">rinstr("abcdeabcdeabcde","e",8)</code> will return 5, because the search for an "<code class="literal">e</code>" starts at position 8 and finds the first one at position 5.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537653"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print rinstr("foofoofoobar","foo")
          </pre><p>This simple example will print <code class="computeroutput">7</code>, because it finds the <span class="emphasis"><em>rightmost</em></span> among the three occurrences of <code class="literal">foo</code> within the string. Note, that</p><div class="informalexample"><pre class="programlisting">
print instr("foofoofoobar","foo")
</pre></div><p>would have printed <code class="computeroutput">1</code>.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537708"></a><h2>See also</h2><p><code class="function"><a href="#ref_instr" title="instr()">instr</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_rtrim"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>rtrim$() — trim spaces at the right end of a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a$=rtrim$(b$)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537758"></a><h2>Description</h2><p>The <code class="function">rtrim$</code>-function removes all whitespace from the right end of a string and returns the result.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537776"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open 1,"foo"
dim lines$(100)
l=1
while(not eof(1))
  input #1 a$
  a$=rtrim$(a$)
  if (right$(line$,1)="\\") then
    line$=line$+" "+a$
  else
    lines$(l)=line$
    l=l+1
    line$=a$
  endif
end while
print "Read ",l," lines"
          </pre><p>This example reads the file <code class="filename">foo</code> allowing for <span class="emphasis"><em>continuation lines</em></span>, which are marked by a <code class="literal">\</code>, which appears as the last character on a line. For convenience whitespace at the right end of a line is trimmed with <code class="function">rtrim</code>.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537823"></a><h2>See also</h2><p><code class="function"><a href="#ref_ltrim" title="ltrim$()">ltrim$</a></code>, <code class="function"><a href="#ref_trim" title="trim$()">trim$</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_s"></a>S</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_screen">screen</a></span><span class="refpurpose"> - as clear screen clears the text window</span></dt><dt><span class="refentrytitle"><a href="#ref_seek">seek()</a></span><span class="refpurpose"> - change the position within an open file</span></dt><dt><span class="refentrytitle"><a href="#ref_sig">sig()</a></span><span class="refpurpose"> - return the sign of its argument</span></dt><dt><span class="refentrytitle"><a href="#ref_sin">sin()</a></span><span class="refpurpose"> - return the sine of its single argument</span></dt><dt><span class="refentrytitle"><a href="#ref_sleep">sleep</a></span><span class="refpurpose"> - pause, sleep, wait for the specified number of seconds</span></dt><dt><span class="refentrytitle"><a href="#ref_split">split()</a></span><span class="refpurpose"> - split a string into many strings</span></dt><dt><span class="refentrytitle"><a href="#ref_sqr">sqr()</a></span><span class="refpurpose"> - compute the square of its argument</span></dt><dt><span class="refentrytitle"><a href="#ref_sqrt">sqrt()</a></span><span class="refpurpose"> - compute the square root of its argument</span></dt><dt><span class="refentrytitle"><a href="#ref_static">static</a></span><span class="refpurpose"> - preserves the value of a variable between calls to a subroutine</span></dt><dt><span class="refentrytitle"><a href="#ref_step">step</a></span><span class="refpurpose"> - specifies the increment step in a for-loop</span></dt><dt><span class="refentrytitle"><a href="#ref_str">str$()</a></span><span class="refpurpose"> - convert a number into a string</span></dt><dt><span class="refentrytitle"><a href="#ref_sub">sub</a></span><span class="refpurpose"> - declare a user defined subroutine</span></dt><dt><span class="refentrytitle"><a href="#ref_switch">switch</a></span><span class="refpurpose"> - select one of many alternatives depending on a value</span></dt><dt><span class="refentrytitle"><a href="#ref_system">system$()</a></span><span class="refpurpose"> - hand a statement over to your operating system and return its output</span></dt><dt><span class="refentrytitle"><a href="#ref_system2">system()</a></span><span class="refpurpose"> - hand a statement over to your operating system and return its exitcode</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_screen"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>screen — as <code class="function">clear screen</code> clears the text window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537903"></a><h2>Description</h2><p>The keyword <code class="function">screen</code> appears only within the sequence <code class="function"><a href="#ref_clear_screen" title="clear screen">clear screen</a></code>; please see there for a description.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537930"></a><h2>See also</h2><p><code class="function"><a href="#ref_clear_screen" title="clear screen">clear screen</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_seek"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>seek() — change the position within an open file</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open 1,"foo"
seek #1,q
seek #1,x,"begin"
seek #1,y,"end"
seek #1,z,"here"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2537983"></a><h2>Description</h2><p>The <code class="function">seek</code>-command changes the position, where the next <code class="function">input</code> (or <code class="function">peek</code>) statement will read from an open file. Usually files are read from the beginning to the end sequentially; however sometimes you may want to depart from this simple scheme. This can be done with the <code class="function">seek</code>-command, allowing you to change the position, where the next piece of data will be read from the file.</p><p><code class="function">seek</code> accepts two or three arguments: The first one is the number of an already open file. The second one is the position where the next read from the file will start. The third argument is optional and specifies the the point from where the position (the second argument) will count. It can be one of:</p><div class="variablelist"><dl><dt><span class="term"><code class="literal">begin</code></span></dt><dd><p>Count from the beginning of the file.</p></dd><dt><span class="term"><code class="literal">end</code></span></dt><dd><p>Count from the end of the file.</p></dd><dt><span class="term"><code class="literal">here</code></span></dt><dd><p>Count from the current position within the file.</p></dd></dl></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538090"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open #1,"count.dat","w"
for a=1 to 10
  print #1,"00000000";
  if (a&lt;10) print #1,";";
next a

dim count(10)
do
  x=int(ran(10))
  i=i+1
  if (mod(i,1000)=0) print ".";
  count(x)=count(x)+1
  curr$=right$("00000000"+str$(count(x)),8)
  seek #1,9*x,"begin"
  print #1,curr$;
loop
          </pre><p>This example increments randomly one of ten counters (in the array <code class="literal">count()</code>); however, the result is always kept and updated within the file <code class="filename">count.dat</code>, so even in case of an unexpected interrupt, the result will not be lost.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538136"></a><h2>See also</h2><p><code class="function"><a href="#ref_tell" title="tell">tell</a></code>, <code class="function"><a href="#ref_open" title="open">open</a></code>, <code class="function"><a href="#ref_print" title="print">print</a></code>, <code class="function"><a href="#ref_peek" title="peek">peek</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_sig"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sig() — return the sign of its argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a=sig(b)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538216"></a><h2>Description</h2><p>Return <code class="literal">+1</code>, <code class="literal">-1</code> or <code class="literal">0</code>, if the single argument is positive, negative or zero.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538244"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
clear screen
dim c$(3):c$(1)="red":c$(2)="white":c$(3)="green"
do
  num=ran(100)-50
  print color(c$(2+sig(num))) num
loop
          </pre><p>This program prints an infinite sequence of random number; positive numbers are printed in green, negative numbers are printed red (an exact zero would be printed white). (With a little extra work, this program could be easily extended into a brokerage system)</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538270"></a><h2>See also</h2><p><code class="function"><a href="#ref_abs" title="abs()">abs</a></code>, <code class="function"><a href="#ref_int" title="int()">int</a></code>, <code class="function"><a href="#ref_frac" title="frac()">frac</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_sin"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sin() — return the sine of its single argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
y=sin(angle)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538341"></a><h2>Description</h2><p>The <code class="function">sin</code>-function expects an angle (in radian, <span class="emphasis"><em>not</em></span> degree) and returns its sine.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538361"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
new curve
for phi=0 to 2*pi step 0.1
  line to 100+90*sin(phi),100+90*cos(phi)
next phi
close curve
          </pre><p>This program draws a circle (ignoring the existence of the <code class="function"><a href="#ref_circle" title="circle">circle</a></code>-command).</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538393"></a><h2>See also</h2><p><code class="function"><a href="#ref_asin" title="asin()">asin</a></code>, <code class="function"><a href="#ref_cos" title="cos()">cos</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_sleep"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sleep — pause, sleep, wait for the specified number of seconds</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
sleep 4
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538454"></a><h2>Description</h2><p>The <code class="function">sleep</code>-command has many different names: You may write <code class="function">pause</code>, <code class="function">sleep</code> or <code class="function">wait</code> interchangable; whatever you write, <span class="application">yabasic</span> will always do exactly the same.</p><p>Therefore you should refer to the entry for the <code class="function"><a href="#ref_pause" title="pause">pause</a></code>-function for further information.</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_split"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>split() — split a string into many strings</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
dim w$(10)
…
num=split(a$,w$())
num=split(a$,w$(),s$)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538545"></a><h2>Description</h2><p>The <code class="function">split</code>-function requires a string (containing the text to be split), a <a href="#ref_array_references" title="References on arrays">reference</a> to a string-array (which will receive the resulting strings, i.e. the <span class="emphasis"><em>tokens</em></span>) and an optional string (with a set of characters, at which to split, i.e. the <span class="emphasis"><em>delimiters</em></span>).</p><p>The <code class="function">split</code>-function regards its first argument (a string) as a list of <span class="emphasis"><em>tokens</em></span> separated by <span class="emphasis"><em>delimiters</em></span> and it will store the list of tokens within the array-reference you have supplied. Note, that the array, which is passed as a reference (<code class="literal">w$()</code> in the synopsis), will be resized accordingly, so that you don't have to figure out the number of tokens in advance. The element at position zero (i.e. <code class="literal">w$(0)</code>) will not be used.</p><p>normally (i.e. if you omit the third, which is the delimiter-argument) the function will regard <span class="emphasis"><em>space</em></span> or <span class="emphasis"><em>tab</em></span> as delimiters for tokens; however by supplying a third argument, you may split at <span class="emphasis"><em>any single</em></span> of the characters within this string. E.g. if you supply <code class="literal">":;"</code> as the third argument, then colon (<code class="literal">:</code>) or semicolon (<code class="literal">;</code>) will delimit tokens.</p><p>Note, that a sequence of separator-characters will produce a sequence of empty tokens; that way, the number of tokens returned will always be one plus the number of separator characters contained within the string. Refer to the closely related <code class="function"><a href="#ref_token" title="token()">token</a></code>-function, if you do not like this behaviour. In some way, the <code class="function">split</code>-function focuses on the separators (other than the <code class="function">token</code>-function, which focuses on the <span class="emphasis"><em>tokens</em></span>), hence its name.</p><p>The second argument is a <a href="#ref_array_references" title="References on arrays">reference</a> on a string-array, where the tokens will be stored; this array will be expanded (or shrinked) to have room for all tokens, if necessary.</p><p>The first argument finally contains the text, that will be split into tokens. The <code class="function">split</code>-function returns the number of tokens that have been found.</p><p>Please see the examples below for some hints on the exact behaviour of the <code class="function">split</code>-function and how it differs from the <code class="function">token</code>-function:</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538728"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "This program will help you to understand, how the"
print "split()-function exactly works and how it behaves"
print "in certain special cases."
print
print "Please enter a line containing tokens separated"
print "by either '=' or '-'"
dim t$(10)
do
  print 
  input "Please enter a line: " l$
  num=split(l$,t$(),"=-")
  print num," Tokens: ";
  for a=1 to num
    if (t$(a)="") then
      print "(EMPTY)";
    else 
      print t$(a);
    endif
    if (a&lt;num) print ","; 
  next a
  print
loop
          </pre><p>This program prints the following output:</p><p>
</p><pre class="screen">
Please enter a line: a
1 Tokens: a

Please enter a line:
0 Tokens:

Please enter a line: ab
1 Tokens: ab

Please enter a line: a=b
2 Tokens: a,b

Please enter a line: a-
2 Tokens: a,(EMPTY)

Please enter a line: a-=
3 Tokens: a,(EMPTY),(EMPTY)

Please enter a line: =a-
3 Tokens: (EMPTY),a,(EMPTY)

Please enter a line: a=-b
3 Tokens: a,(EMPTY),b

Please enter a line: a--b-
4 Tokens: a,(EMPTY),b,(EMPTY)

Please enter a line: -a==b-c==
7 Tokens: (EMPTY),a,(EMPTY),b,c,(EMPTY),(EMPTY)
</pre><p>
</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538780"></a><h2>See also</h2><p><code class="function"><a href="#ref_token" title="token()">token</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_sqr"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sqr() — compute the square of its argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a=sqr(b)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538830"></a><h2>Description</h2><p>The <code class="function">sqr</code>-function computes the square of its numerical argument (i.e. it multiplies its argument with itself).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538848"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 10
  print a,sqr(a),a**2
next a
          </pre><p>As you may see from the output, <code class="function">sqr</code> can be written as <code class="function">**2</code> (or <code class="function">^2</code>) too.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538886"></a><h2>See also</h2><p><code class="function"><a href="#ref_sqrt" title="sqrt()">sqrt</a></code>, <code class="function"><a href="#ref_pow" title="** or ^">**</a></code>, <code class="function"><a href="#ref_pow" title="** or ^">^</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_sqrt"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sqrt() — compute the square root of its argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">to be written</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538956"></a><h2>Description</h2><p>The <code class="function">sqrt</code>-function computes the square root of its numerical argument.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2538973"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 5
  print a,sqrt(a),a**(1/2)
next a
          </pre><p>As you may see from the output, <code class="function">sqrt</code> can be written as <code class="function">**(1/2)</code> (or <code class="function">^(1/2)</code>) too.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2539012"></a><h2>See also</h2><p><code class="function"><a href="#ref_sqr" title="sqr()">sqr</a></code>, <code class="function"><a href="#ref_pow" title="** or ^">**</a></code>, <code class="function"><a href="#ref_pow" title="** or ^">^</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_static"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>static — preserves the value of a variable between calls to a subroutine</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
sub foo()

  static a

  …

end sub 
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2539084"></a><h2>Description</h2><p>The <code class="function">static</code> keyword can be used within subroutines to mark variables as <span class="emphasis"><em>static</em></span>. This has two effects: First, the variable is <span class="emphasis"><em>local</em></span> to the subroutine, i.e. its value is not know outside the subroutine (this is the effect of the <code class="function"><a href="#ref_local" title="local">local</a></code> keyword). Second, the <code class="function">static</code>-keyword arranges things, so that the variable keeps its value between invocations of the subroutine (this is different from the <code class="function">local</code>-keyword).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2539134"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
foo()
foo()
foo()

sub foo()
  static a
  local b
  a=a+1
  b=b+1
  print a,b
end sub
          </pre><p>This program shows the difference between <code class="function">static</code> and <code class="function">local</code> variables within a subroutine; it produces this output:</p><p>
</p><pre class="screen">1 1
2 1
3 1
</pre><p>
</p><p>The output shows, that the <code class="function">static</code> variable <code class="varname">a</code> keeps its value between subroutine calls, whereas <code class="varname">b</code> is initialized with the value 0 at every call to the subroutine <code class="function">foo</code>.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2539201"></a><h2>See also</h2><p><code class="function"><a href="#ref_sub" title="sub">sub</a></code>, <code class="function"><a href="#ref_local" title="local">local</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_step"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>step — specifies the increment step in a for-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
for a=1 to 10 step 3
  …
next a
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2539263"></a><h2>Description</h2><p>Specify, by which amount the loop-variable of a <code class="function"><a href="#ref_for" title="for">for</a></code>-loop will be incremented at each step.</p><p>The <code class="function">step</code> (as well as the lower and upper bound) are computed anew in each step; this is not common, but possible, as the example below demonstrates.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2539296"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for x=1 to 1000 step y
  y=x+y
  print x," ",y," ";
next x
print
          </pre><p>This program computes the fibonacci numbers between 1 and 1000.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2539317"></a><h2>See also</h2><p><code class="function"><a href="#ref_for" title="for">for</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_str"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>str$() — convert a number into a string</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a$=str$(a)
b$=str$(x,"##.###")
b$=str$(x,"###,###.##")
b$=str$(x,"###,###.##","_.")
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2539368"></a><h2>Description</h2><p>The <code class="function">str$</code>-function accepts a numeric argument and returns it as a string. This conversion between number and string can be controlled with the optional third argument (the <span class="emphasis"><em>format</em></span> argument). See the following table of examples to learn about valid values of this argument. Note, that those examples fall in one of two categories: <span class="emphasis"><em>C-style</em></span> and <span class="emphasis"><em>basic-style</em></span>; the first 4 examples in the table below are C-style, the rest of the examples are basic-style. For more information on the C-style formats, you may refer to your favorite documentation on the C programming language. The basic-style formats are much simpler, they just depict the desired output, marking digits with '<code class="literal">#</code>'; groups of (usually three) digits may be separated with colons ('<code class="literal">,</code>'), the decimal dot must be marked by a literal dot ('<code class="literal">.</code>'). Moreover these characters (colons and dot) may be replaced by other characters to satisfy the needs of non-english (e.g. german) languages; see the examples below.</p><p>Note, that for clarity, each space in the result has been replaced by the letter 'x', because it would be hard to figure out, how many spaces are produced <span class="emphasis"><em>exactly</em></span> otherwise.</p><div class="table"><a id="id2539436"></a><p class="title"><b>Table 6.2. Examples for the format argument</b></p><table summary="Examples for the format argument" border="1"><colgroup><col /><col /></colgroup><thead><tr><th><code class="function">Example string</code></th><th><code class="function">Result for converting 1000*<code class="constant">pi</code></code></th><th><code class="function">Description</code></th></tr></thead><tbody><tr><td><code class="literal">%2.5f</code></td><td><code class="literal">3141.59265</code></td><td>The '<code class="literal">2</code>' determines the minimum length of the output; but if needed (as in the example) the output can be longer. The '<code class="literal">5</code>' is the number of digits after the decimal point.</td></tr><tr><td><code class="literal">%12.5f</code></td><td><code class="literal">xx3141.59265</code></td><td>Two spaces (which appear as '<code class="literal">x</code>') are added to pad the output to the requested length of 12 characters.</td></tr><tr><td><code class="literal">%012.5g</code></td><td><code class="literal">0000003141.6</code></td><td>The '<code class="literal">g</code>' requests, that the precision ('<code class="literal">5</code>') specifies the <span class="emphasis"><em>overall</em></span> number of digits (before and after the decimal point).</td></tr><tr><td><code class="literal">%-12.5f</code></td><td><code class="literal">3141.59265xx</code></td><td>The '<code class="literal">-</code>' requests the output to be left-centered (therefor the filling space appears at the right).</td></tr><tr><td><code class="literal">#####.##</code></td><td><code class="literal">x3141.59</code></td><td>Each '<code class="literal">#</code>' specifies a digit (either before or after the dot), the '<code class="literal">.</code>' specifies the position of the dot. As 1000*<code class="constant">pi</code> does not have enough digits, the 5 requested digits before the dot are filled up with a space (which shows up as an '<code class="literal">x</code>').</td></tr><tr><td><code class="literal">##,###.##</code></td><td><code class="literal">x3,141.59</code></td><td>Nearly the same as above, but the colon from the format shows up within the result.</td></tr><tr><td><code class="literal">##,###.##</code> and an <span class="emphasis"><em>additional</em></span> argument of <code class="literal">".,"</code></td><td><code class="literal">x3.141,59</code></td><td>Similar to the example above, but colon and dot are replaced with dot and colon respectivly.</td></tr><tr><td><code class="literal">##,###.##</code> and an <span class="emphasis"><em>additional</em></span> argument of <code class="literal">"_,"</code></td><td><code class="literal">x3_141,59</code></td><td>Similar to the example above, but colon and dot are replaced with underscore and colon respectivly.</td></tr><tr><td><code class="literal">#####</code></td><td><code class="literal">x3142</code></td><td>The format string does not contain a dot, and therefore the result does not have any fractional digits.</td></tr><tr><td><code class="literal">##.###</code></td><td><code class="literal">##.###</code></td><td>As 1000*<code class="constant">pi</code> has 4 digits in front of the decimal dot and the format only specifies 2, <span class="application">yabasic</span> does not know what to do; therefore it chooses just to reproduce the format string.</td></tr></tbody></table></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2539793"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
do
  input "Please enter a format string: " f$
  a$=str$(1000*pi,f$)
  for a=1 to len(a$)
    if (mid$(a$,a,1)=" ") mid$(a$,a,1)="x"
  next a
  print a$
loop
          </pre><p>This is the program, that has been used to get the results shown in the table above.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2539817"></a><h2>See also</h2><p><code class="function"><a href="#ref_print" title="print">print</a></code>, <code class="function"><a href="#ref_using" title="using">using</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_sub"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>sub — declare a user defined subroutine</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
foo(2,"hello")

…

sub foo(bar,baz$)
  …
  return qux
  …
end sub
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2539878"></a><h2>Description</h2><p>The <code class="function">sub</code>-keyword starts the definition of a <span class="emphasis"><em>user defined subroutine</em></span>. With user defined subroutines you are able to somewhat extend <span class="application">yabasic</span> with your own commands or functions. A subroutine accepts arguments (numbers or strings) and returns a number or a string (however, you are not required to assign the value returned to a variable).</p><p>The name of the subroutine follows after the keyword <code class="function">sub</code>. If the name (in the synopsis: <code class="function">foo</code>) ends on a '<code class="literal">$</code>', the subroutine should return a string (with the <code class="function"><a href="#ref_return" title="return">return</a></code>-statement), otherwise a number.</p><p>After the name of the subroutine
<span class="application">yabasic</span> requires a pair of braces; within those
braces you may specify a list of parameters, for which values can (but need
not) be included when calling the subroutine. If you omit one of those
parameters when calling such a subroutine, it assumes the value zero (for
numeric parameters) or the empty string (for string-parameters). However from
the special variable <code class="function"><a href="#ref_numparams" title="numparams">numparams</a></code> you may find out, how many arguments have really been passed when calling the subroutine.</p><p>Parameters of a subroutine are always local variables (see the keyword <code class="function"><a href="#ref_local" title="local">local</a></code> for more explanation).</p><p>From within the subroutine you may return any time with the keyword <code class="function"><a href="#ref_return" title="return">return</a></code>; along with the <code class="function">return</code>-keyword you may specify the return value. Note that more than one <code class="function">return</code> is allowed within a single subroutine.</p><p>Finally, the keyword <code class="function">end sub</code> ends the subroutine definition. Note, that the definition of a subroutine <span class="emphasis"><em>need not</em></span> appear within the program <span class="emphasis"><em>before</em></span> the first call to this sub.</p><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>As <span class="emphasis"><em>braces</em></span> have two uses in <span class="application">yabasic</span> (i.e. for supplying arguments to a subroutine as well as to list the indices of an array). <span class="application">yabasic</span> can not tell apart an array from a subroutine with the same name. Therefore you <span class="emphasis"><em>cannot</em></span> define a subroutine with the same name as an array !</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540061"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
p=2
do 
  if (is_prime(p)) print p
  p=p+1
loop

sub is_prime(a)
  local b
  for b=2 to sqrt(a)
    if (frac(a/b)=0) return false
  next b
  return true
end sub
          </pre><p>This example is not the recommended way to compute prime numbers. However it gives a nice demonstration of using a subroutine.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540085"></a><h2>See also</h2><p><code class="function"><a href="#ref_local" title="local">local</a></code>, <code class="function"><a href="#ref_static" title="static">static</a></code>, <code class="function"><a href="#ref_peek" title="peek">peek</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_switch"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>switch — select one of many alternatives depending on a value</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
switch a
  case 1
  case 2
  …
end switch

…

switch a$
  case "a"
  case "b"
end switch
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540159"></a><h2>Description</h2><p>The <code class="function">switch</code>-statement selects one of many codepaths depending on a numerical or string expression. I.e. it takes an expression (either numeric or string) and compares it with a series of values, each wrapped within a <code class="function"><a href="#ref_case" title="case">case</a></code>-clause. If the expression equals the value given in a <code class="function">case</code>-clause, the subsequent statements are executed.</p><p>The <code class="function"><a href="#ref_default" title="default">default</a></code>-clause allows to specify commands, which should be executed, if none of <code class="function">case</code>-clauses matches.</p><p>Note, that many <code class="function">case</code>-clauses might be clustered (e.g. <code class="literal">case "a":case "b":case "c"</code>). Or put another way: You need a <code class="function">break</code>-statement at the end of a <code class="function">case</code>-branch, if you do not want to run into the next <code class="function">case</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540251"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a single digit: " n
switch n
  case 0:print "zero":break
  case 1:print "one":break
  case 2:print "two":break
  case 3:print "three":break
  case 4:print "four":break
  case 5:case 6: case 7:case 8:case 9
    print "Much !":break
  default:print "Hey ! That was more than a single digit !"
end switch 
          </pre><p>This example translates a single digit into a string; note, how the cases 5 to 7 are clustered.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540278"></a><h2>See also</h2><p><code class="function"><a href="#ref_switch" title="switch">switch</a></code>, <code class="function"><a href="#ref_case" title="case">case</a></code>, <code class="function"><a href="#ref_break" title="break">break</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_system"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>system$() — hand a statement over to your operating system and return its output</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print system$("dir")
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540350"></a><h2>Description</h2><p>The <code class="function">system$</code>-command accepts a single string argument, specifying a command, that can be found and executed by your operating system. It returns the output of this command as one big string.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540368"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter the name of a directory: " d$
print
print "This is the contents of the '"+d$+"':"
print system$("dir "+d$)
          </pre><p>This example lists the contents of a directory, employing the <span class="application">dir</span>-command  (which is about the only program, that is known under Unix as well as Windows).</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540398"></a><h2>See also</h2><p><code class="function"><a href="#ref_system" title="system$()">system</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_system2"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>system() — hand a statement over to your operating system and return its exitcode</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
ret=system("foo")
system("bar")
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540449"></a><h2>Description</h2><p>The <code class="function">system</code>-command accepts a single string argument, which specifies a command to be executed. The function will return the exitcode of the command; its output (if any) will be lost.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540468"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "Please enter the name of the file, that should be deleted."
input f$
if (system("rm "+f$+" &gt;/dev/null 2&gt;&amp;1")) then
  print "Error !"
else
  print "okay."
endif
          </pre><p>This program is Unix-specific: It uses the Unix-command <code class="function">rm</code> to remove a file.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540497"></a><h2>See also</h2><p><code class="function"><a href="#ref_system2" title="system()">system$</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_t"></a>T</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_tan">tan()</a></span><span class="refpurpose"> - return the tangens of its argument</span></dt><dt><span class="refentrytitle"><a href="#ref_tell">tell</a></span><span class="refpurpose"> - get the current position within an open file</span></dt><dt><span class="refentrytitle"><a href="#ref_text">text</a></span><span class="refpurpose"> - write text into your graphic-window</span></dt><dt><span class="refentrytitle"><a href="#ref_then">then</a></span><span class="refpurpose"> - tell the long from the short form of the if-statement</span></dt><dt><span class="refentrytitle"><a href="#ref_time">time$</a></span><span class="refpurpose"> - return a string containing the current time</span></dt><dt><span class="refentrytitle"><a href="#ref_to">to</a></span><span class="refpurpose"> - this keyword appears as part of other statements</span></dt><dt><span class="refentrytitle"><a href="#ref_token">token()</a></span><span class="refpurpose"> - split a string into multiple strings</span></dt><dt><span class="refentrytitle"><a href="#ref_triangle">triangle</a></span><span class="refpurpose"> - draw a triangle</span></dt><dt><span class="refentrytitle"><a href="#ref_trim">trim$()</a></span><span class="refpurpose"> - remove leading and trailing spaces from its argument</span></dt><dt><span class="refentrytitle"><a href="#ref_true">true</a></span><span class="refpurpose"> - a constant with the value of 1</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_tan"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>tan() — return the tangens of its argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
foo=tan(bar)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540561"></a><h2>Description</h2><p>The <code class="function">tan</code>-function computes the tangens of its arguments (which should be specified in radian).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540578"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=0 to 45
  print tan(a*pi/180)
next a
          </pre><p>This example simply prints the tangens of all angles between 0 and 45 degree.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540599"></a><h2>See also</h2><p><code class="function"><a href="#ref_atan" title="atan()">atan</a></code>, <code class="function"><a href="#ref_sin" title="sin()">sin</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_tell"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>tell — get the current position within an open file</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open #1,"foo"
  …
position=tell(#1)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540661"></a><h2>Description</h2><p>The <code class="function">tell</code>-function requires the number of an open file as an argument. It returns the position (counted in bytes, starting from the beginning of the file) where the next read will start.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540679"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open #1,"foo","w"
print #1 "Hello World !"
close #1

open #1,"foo"
seek #1,0,"end"
print tell(#1)
close 1
          </pre><p>This example (mis)uses <code class="function">tell</code> to get the size of the file. The <code class="function">seek</code> positions the file pointer at the end of the file, therefor the call to <code class="function">tell</code> returns the total length of the file.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540720"></a><h2>See also</h2><p><code class="function"><a href="#ref_tell" title="tell">tell</a></code>, <code class="function"><a href="#ref_open" title="open">open</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_text"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>text — write text into your graphic-window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
text x,y,"foo"
text x,y,"foo","lb"
text x,y,"foo","cc","font"
text x,y,"foo","font","rt"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540782"></a><h2>Description</h2><p>The <code class="function">text</code>-commands displays a text-string (the third argument) at the given position (the first two arguments) within an already <code class="function"><a href="#ref_open_window" title="open window">open</a></code>ed <code class="function"><a href="#ref_open_window" title="open window">window</a></code>. The font to be used can be optionally specified as either the fourth or fifth argument (<code class="literal">"font"</code> in the example above). A font specified this way will also be used for any subsequent <code class="function">text</code>-commands, as long as they do not specify a font themselves.</p><p>The fourth or fifth optional argument (<code class="literal">"lb"</code> in the example above) can be used to specify the alignment of the text with respect to the specified position. This argument is always two characters long: The first character specifies the horizontal alignment and can be either <code class="literal">l</code>, <code class="literal">r</code> or <code class="literal">c</code>, which stand for <em class="wordasword">left</em>, <em class="wordasword">right</em> or <em class="wordasword">center</em>. The second character specifies the vertical alignment and can be one of <code class="literal">t</code>, <code class="literal">b</code> or <code class="literal">c</code>, which stand for <em class="wordasword">top</em>, <em class="wordasword">bottom</em> or <em class="wordasword">center</em> respectively. If you omit this alignment argument, the default <code class="literal">"lb"</code> applies; however this default may be changed with <code class="function"><a href="#ref_poke" title="poke">poke "textalign","xx"</a></code></p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540924"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 500,200
clear screen
data "lt","lc","lb","ct","cc","cb","rt","rc","rb"
for a=1 to 9
  read align$	
  print "Alignment: ",align$
  line 50*a-15,100,50*a+15,100
  line 50*a,85,50*a,115
  text 50*a,100,"Test",align$
  inkey$ 
next a
          </pre><p>This program draws nine crosses and writes the same text at each; however it goes through all possible nine alignment strings, showing their effect.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2540950"></a><h2>See also</h2><p><code class="function"><a href="#ref_open_window" title="open window">open window</a></code>, <code class="function"><a href="#ref_peek" title="peek">peek</a></code>, <code class="function"><a href="#ref_poke" title="poke">poke</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_then"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>then — tell the long from the short form of the <code class="function">if</code>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
if (a&lt;b) then
  …
endif
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541028"></a><h2>Description</h2><p>The keyword <code class="function">then</code> is part of the <code class="function"><a href="#ref_if" title="if">if</a></code>-statement; please see there for further explanations. However, not every <code class="function">if</code>-statement requires the keyword <code class="function">then</code>: If the keyword <code class="function">then</code> is present, the <code class="function">if</code>-clause may extend over more than one line, and the keyword <code class="function">endif</code> is required to end it. If the keyword <code class="function">then</code> is <span class="emphasis"><em>not</em></span> present, the <code class="function">if</code>-statement extends up to the end of the line, and any <code class="function">endif</code> would be an error.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541108"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
if (1&lt;2) then 
  print "Hello ";
endif

if (2&lt;3) print "world"
if (2&lt;1)
  print "!"
          </pre><p>This example prints <code class="literal">Hello world</code>. Note, that no exclamation mark (<code class="literal">!</code>) is printed, which might come as a surprise and may be changed in future versions of <span class="application">yabasic</span>.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541149"></a><h2>See also</h2><p><code class="function"><a href="#ref_if" title="if">if</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_time"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>time$ — return a string containing the current time</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print time$
print time$()
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541200"></a><h2>Description</h2><p>The <code class="function">time$</code> function returns the current time in four fields separated by hyphens '<code class="literal">-</code>'. The fields are:</p><p>
</p><div class="itemizedlist"><ul type="disc"><li><p>The current hour in the range from 0 to 23, padded with zeroes (e.g. <code class="literal">00</code> or <code class="literal">04</code>) to a length of two characters.</p></li><li><p>The number of minutes, padded with zeroes.</p></li><li><p>The number of seconds, padded with zeroes.</p></li><li><p>The number of seconds, that have elapsed since the program has been started. This value increases as long as your program runs and is therefore unbound and not padded with zeroes.</p></li></ul></div><p>
</p><p>At the time of writing this documentation, <code class="function">time$</code> returns <code class="computeroutput">22-58-53-0</code>. Note, that the first three of the four fields returned by <code class="function">time$</code> have a fixed width; therefore it is easy to extract some fields with the usual string-functions <code class="function"><a href="#ref_mid" title="mid$()">mid$</a></code> (and others).</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541308"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "Hello it is ",time$
print "An empty for-loop with ten million iterations takes ";
s=val(mid$(time$,10))
for a=1 to 10000000:next a
e=val(mid$(time$,10))
print e-s," seconds"
          </pre><p>This program benchmarks the <code class="function">for</code>-loop and uses the fourth field of the string returned by <code class="function">time$</code>.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541343"></a><h2>See also</h2><p><code class="function"><a href="#ref_date" title="date$">date</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_to"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>to — this keyword appears as part of other statements</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
for a=1 to 100 step 2
  …
next a

line x,y to a,b
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541395"></a><h2>Description</h2><p>The <code class="function">to</code>-keyword serves two purposes (which are not related at all):</p><div class="itemizedlist"><ul type="disc"><li><p>within <code class="function"><a href="#ref_for" title="for">for</a></code>-statements, to specify the upper bound of the loop.</p></li><li><p>Within any graphical command (e.g. <code class="function">line</code>), that requires two points (i.e. four numbers) as arguments, a comma '<code class="literal">,</code>' might be replaced with the keyword <code class="literal">to</code>. I.e. instead of <code class="literal">100,100,200,200</code> you may write <code class="literal">100,100 to 200,200</code> in such commands.</p></li></ul></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541471"></a><h2>Example</h2><p>Please see the command listed under "See also" for examples.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541482"></a><h2>See also</h2><p><code class="function"><a href="#ref_for" title="for">for</a></code>, <code class="function"><a href="#ref_line" title="line">line</a></code>, <code class="function"><a href="#ref_rectangle" title="rectangle">rectangle</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_token"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>token() — split a string into multiple strings</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
dim w$(10)
…
num=token(a$,w$())
num=token(a$,w$(),s$)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541553"></a><h2>Description</h2><p>The <code class="function">token</code>-function accepts a string (containing the text to be split), a <a href="#ref_array_references" title="References on arrays">reference</a> to a string-array (which will receive the resulting strings, i.e. the <span class="emphasis"><em>tokens</em></span>) and an optional string (with a set of characters, at which to split, i.e. the <span class="emphasis"><em>delimiters</em></span>).</p><p>The <code class="function">token</code>-function regards its first argument as a list of <span class="emphasis"><em>tokens</em></span> separated by <span class="emphasis"><em>delimiters</em></span> and it will store the list of tokens within the array-reference that has been supplied. Note, that the array, which is passed as a reference (<code class="literal">w$()</code> in the synopsis), will be resized accordingly, so that you don't have to figure out the number of tokens in advance. The element at position zero (i.e. <code class="literal">w$(0)</code>) will not be used.</p><p>Normally (i.e. if you omit the third, the delimiter-argument) the function will regard <span class="emphasis"><em>space</em></span> or <span class="emphasis"><em>tab</em></span> as delimiters for tokens; however by supplying a third argument, you may split at <span class="emphasis"><em>any single</em></span> of the characters within this string. E.g. if you supply <code class="literal">":;"</code> as the third argument, then colon (<code class="literal">:</code>) or semicolon (<code class="literal">;</code>) will delimit tokens.</p><p>Note, that <code class="function">token</code> will never produce empty tokens, even if two or more separators follow in sequence. Refer to the closely related <code class="function"><a href="#ref_token" title="token()">split</a></code>-function, if you do not like this behaviour. In some way, the <code class="function">token</code>-function focuses on the tokens and not on the separators (other than the <code class="function">split</code>-function, which focuses on the separators).</p><p>The second argument is a <a href="#ref_array_references" title="References on arrays">reference</a> on a string-array, where the tokens will be stored; this array will be expanded (or shrinked) as necessary to have room for all tokens.</p><p>The first argument finally contains the text, that will be split into tokens. The <code class="function">token</code>-function returns the number of tokens, that have been found.</p><p>Please see the examples below for some hints on the exact behaviour of the <code class="function">token</code>-function and how it differs from the <code class="function">split</code>-function:</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541736"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "This program will help you to understand, how the"
print "token()-function exactly works and how it behaves"
print "in certain special cases."
print
print "Please enter a line containing tokens separated"
print "by either '=' or '-'"
dim t$(10)
do
  print 
  input "Please enter a line: " l$
  num=token(l$,t$(),"=-")
  print num," Tokens: ";
  for a=1 to num
    if (t$(a)="") then
      print "(EMPTY)";
    else 
      print t$(a);
    endif
    if (a&lt;num) print ","; 
  next a
  print
loop
          </pre>
	    This program prints the following output:
	    <p>
</p><pre class="screen">
Please enter a line: a
1 Tokens: a

Please enter a line:
0 Tokens:

Please enter a line: ab
1 Tokens: ab

Please enter a line: a=b
2 Tokens: a,b

Please enter a line: a-
1 Tokens: a

Please enter a line: a-=
1 Tokens: a

Please enter a line: =a-
1 Tokens: a

Please enter a line: a=-b
2 Tokens: a,b

Please enter a line: a--b-
2 Tokens: a,b

Please enter a line: -a==b-c==
3 Tokens: a,b,c
</pre><p>
</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541784"></a><h2>See also</h2><p><code class="function"><a href="#ref_split" title="split()">split</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_triangle"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>triangle — draw a triangle</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open window 100,100
triangle 100,100,50,50,100,50
fill triangle 50,100,100,50,200,200
clear fill triangle 20,20,10,10,200,200
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541836"></a><h2>Description</h2><p>The <code class="function">triangle</code>-command draws a triangle; it requires 6 parameters: The x- and y-coordinates of the three points making up the triangle. With the optional keywords <code class="function">clear</code> and <code class="function">fill</code> (which may appear both and in any sequence) the triangle can be cleared and filled respectively.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541868"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open window 200,200
do 
  phi=phi+0.2
  i=i+2
  color mod(i,255),mod(85+2*i,255),mod(170+3*i,255)
  dx=100*sin(phi):dy=20*cos(phi)
  fill triangle 100+20*sin(phi),100+20*cos(phi),100-20*sin(phi),100-20*cos(phi),100-80*cos(phi),100+80*sin(phi)
  sleep 0.1
loop
          </pre><p>This example draws a colored triangles until you get exhausted.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541893"></a><h2>See also</h2><p><code class="function"><a href="#ref_open_window" title="open window">open window</a></code>, <code class="function"><a href="#ref_open_printer" title="open printer">open printer</a></code>, <code class="function"><a href="#ref_line" title="line">line</a></code>, <code class="function"><a href="#ref_circle" title="circle">circle</a></code><code class="function">, <a href="#ref_rectangle" title="rectangle">rectangle</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_trim"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>trim$() — remove leading and trailing spaces from its argument</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
a$=trim$(b$)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2541985"></a><h2>Description</h2><p>The <code class="function">trim$</code>-function removes all whitespaces from the left and from the right end of a string and returns the result. Calling <code class="function">trim$</code> is equivalent to calling <code class="function">rtrim$(ltrim$())</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542015"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
do
  input "Continue ? Please answer yes or no: " a$
  a$=lower$(trim$(a$))
  if (len(a$)&gt;0 and a$=left$("no",len(a$)) exit
loop
          </pre><p>This example asks for an answer (<code class="literal">yes</code> or <code class="literal">no</code>) and removes spaces with <code class="function">trim$</code> to make the comparison with the string <code class="literal">"no"</code> more bulletproof.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542062"></a><h2>See also</h2><p><code class="function"><a href="#ref_ltrim" title="ltrim$()">ltrim$</a></code>, <code class="function"><a href="#ref_rtrim" title="rtrim$()">rtrim$</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_true"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>true — a constant with the value of 1</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
okay=true
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542123"></a><h2>Description</h2><p>The constant <code class="function">true</code> can be assigned to variables which will later appear in conditions (e.g. an <code class="function">if</code>-statement.</p><p><code class="function">true</code> may also be written as <code class="function">TRUE</code> or even <code class="function">TrUe</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542167"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a string of all upper letters: " a$
if (is_upper(a$)) print "Okay"

sub is_upper(a$)
  if (a$=upper$(a$)) return true
  return false
end sub
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542185"></a><h2>See also</h2><p><code class="function"><a href="#ref_false" title="false">false</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_u"></a>U</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_until">until</a></span><span class="refpurpose"> - end a repeat-loop</span></dt><dt><span class="refentrytitle"><a href="#ref_upper">upper$()</a></span><span class="refpurpose"> - convert a string to upper case</span></dt><dt><span class="refentrytitle"><a href="#ref_using">using</a></span><span class="refpurpose"> - Specify the format for printing a number</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_until"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>until — end a <code class="function">repeat</code>-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
repeat 
  …
until (…)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542255"></a><h2>Description</h2><p>The <code class="function">until</code>-keyword ends a loop, which has been introduced by the <code class="function"><a href="#ref_repeat" title="repeat">repeat</a></code>-keyword. <code class="function">until</code> requires a condition in braces (or an expression, see <a href="#ref_conditions_and_expressions" title="Conditions and expressions">here</a> for details) as an argument; the loop will continue <span class="emphasis"><em>until</em></span> this condition evaluates to true.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542301"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
c=1
s=1
repeat
  l=c
  s=-(s+sig(s))
  c=c+1/s
  print c
until(abs(l-c)&lt;0.000001)
          </pre><p>This program calculates the sequence 1/1-1/2+1/3-1/4+1/5-1/6+1/7-1/8+ … ; please let me know, if you know against which value this converges.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542326"></a><h2>See also</h2><p><code class="function"><a href="#ref_repeat" title="repeat">repeat</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_upper"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>upper$() — convert a string to upper case</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
u$=upper$(a$)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542376"></a><h2>Description</h2><p>The <code class="function">upper$</code>-function accepts a single string argument and converts it to all upper case.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542394"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
line input "Please enter a sentence without the letter 'e': " l$
p=instr(upper$(l$),"E")
if (p) then
  l$=lower$(l$)
  mid$(l$,p,1)="E"
  print "Hey, you are wrong, see here!"
  print l$
else
  print "Thanks."
endif
          </pre><p>This program asks for a sentence and marks the first (if any) occurrence of the letter 'e' by coverting it to upper case (in contrast to the rest of the sentence, which is converted to lower case).</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542420"></a><h2>See also</h2><p><code class="function"><a href="#ref_lower" title="lower$()">lower$</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_using"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>using — Specify the format for printing a number</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print a using "##.###"
print a using("##.###",",.")
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542471"></a><h2>Description</h2><p>The <code class="function">using</code>-keyword may appear as part of the <code class="function">print</code>-statement and specifies the format (e.g. the number of digits before and after the decimal dot), which should be used to print the number.</p><p>The possible values for the format argument (<code class="literal">"##.###"</code> in the synopsis above) are described within the entry for the <code class="function"><a href="#ref_str" title="str$()">str$</a></code>-function; especially the second line in the synopsis (<code class="literal">print a using("##.###",",.")</code>) will become clear after referring to <code class="function">str$</code>. In fact the <code class="function">using</code> clause is closely related to the <code class="function">str$</code>-function; the former can always be rewritten using the latter; i.e. <code class="literal">print foo using bar$</code> is always equivalent to <code class="literal">print str$(foo,bar$)</code>. Therefore you should check out <code class="function"><a href="#ref_str" title="str$()">str$</a></code> to learn more.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542568"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
for a=1 to 10
  print sqrt(ran(10000*a)) using "#########.#####"
next a
          </pre><p>This example prints a column of square roots of random number, nicely aligned at the decimal dot.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542590"></a><h2>See also</h2><p><code class="function"><a href="#ref_print" title="print">print</a></code>, <code class="function"><a href="#ref_str" title="str$()">str$</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_v"></a>V</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_val">val()</a></span><span class="refpurpose"> - converts a string to a number</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_val"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>val() — converts a string to a number</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=val(x$)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542663"></a><h2>Description</h2><p>The <code class="function">val</code>-function checks, if the start of
its string argument forms a floating point number and then returns this
number. The string therefore has to start with digits (only whitespace in front is allowed), otherwise the <code class="function">val</code>-function returns zero.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542689"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
input "Please enter a length, either in inches (in) or centimeters (cm) " l$
if (right$(l$,2)="in") then
  l=val(l$)*2.51
else
  l=val(l$)
print "You have entered ",l,"cm."
          </pre><p>This example queries for a length and checks, if it has been specified in inches or centimeters. The length is then converted to centimeters.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542713"></a><h2>See also</h2><p><code class="function"><a href="#ref_str" title="str$()">str$</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_w"></a>W</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_wait">wait</a></span><span class="refpurpose"> - pause, sleep, wait for the specified number of seconds</span></dt><dt><span class="refentrytitle"><a href="#ref_wend">wend</a></span><span class="refpurpose"> - end a while-loop</span></dt><dt><span class="refentrytitle"><a href="#ref_while">while</a></span><span class="refpurpose"> - start a while-loop</span></dt><dt><span class="refentrytitle"><a href="#ref_origin">window origin</a></span><span class="refpurpose"> - move the origin of a window</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_wait"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>wait — pause, sleep, wait for the specified number of seconds</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
wait 4
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542777"></a><h2>Description</h2><p>The <code class="function">wait</code>-command has many different names: You may write <code class="function">pause</code>, <code class="function">sleep</code> or <code class="function">wait</code> interchangeably; whatever you write, <span class="application">yabasic</span> will always do exactly the same.</p><p>Therefore you should refer to the entry for the <code class="function"><a href="#ref_pause" title="pause">pause</a></code>-function for further information.</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_wend"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>wend — end a <code class="function"><a href="#ref_while" title="while">while</a></code>-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
while(a&lt;b)
  …
wend
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542878"></a><h2>Description</h2><p>The <code class="function">wend</code>-keyword marks the end of a <code class="function"><a href="#ref_while" title="while">while</a></code>-loop. Please see the <code class="function"><a href="#ref_while" title="while">while</a></code>-keyword for more details.</p><p><code class="function">wend</code> can be written as <code class="function">end while</code> or even <code class="function">end-while</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542934"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
line input "Please enter a sentence: " a$
p=instr(a$,"e")
while(p)
  mid$(a$,p,1)="E"
  p=instr(a$,"e")
wend
print a$
          </pre><p>This example reads a sentence and converts every occurrence of the letter <code class="literal">e</code> into uppercase (<code class="literal">E</code>).</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2542968"></a><h2>See also</h2><p><code class="function"><a href="#ref_while" title="while">while</a></code> (which is just the following entry).</p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_while"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>while — start a <code class="function">while</code>-loop</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
while(…)
  …
wend
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543027"></a><h2>Description</h2><p>The <code class="function">while</code>-keyword starts a <code class="function">while</code>-loop, i.e. a loop that is executed as long as the condition (which is specified in braces after the keyword <code class="function">while</code>) evaluates to <code class="constant">true</code>.</p><p>Note, that the body of such a <code class="function">while</code>-loop will not be executed at all, if the condition following the <code class="function">while</code>-keyword is not true initially.</p><p>If you want to leave the loop prematurely, you may use the <code class="function"><a href="#ref_break" title="break">break</a></code>-statement.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543092"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
open #1,"foo"
while(!eof(1))
  line input #1 a$
  print a$
wend
          </pre><p>This program reads the file <code class="literal">foo</code> and prints it line by line.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543119"></a><h2>See also</h2><p><code class="function"><a href="#ref_until" title="until">until</a></code>, <code class="function"><a href="#ref_break" title="break">break</a></code>, <code class="function"><a href="#ref_wend" title="wend">wend</a></code>, <code class="function"><a href="#ref_do" title="do">do</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_origin"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>origin — move the origin of a window</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
open window 200,200
origin "cc"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543200"></a><h2>Description</h2><p>The <code class="function">origin</code>-command applies to graphic windows and moves the origin of the coordinate system to one of nine point within the window. The normal position of the origin is in the upper left corner of the window; however in some cases this is inconvenient and moving the origin may save you from subtracting a constant offset from all of your coordinates.</p><p>However, you may not move the origin to an arbitrary position; in horizontal position there are only three positions: left, center and right, which are decoded by the letters <code class="literal">l</code>, <code class="literal">c</code> and <code class="literal">r</code>. In vertical position the allowed positions are top, center and bottom; encoded by the letters <code class="literal">t</code>, <code class="literal">c</code> and <code class="literal">b</code>. Taking the letters together, you arrive at a string, which might be passed as an argument to the command; e.g. <code class="literal">"cc"</code> or <code class="literal">"rt"</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543276"></a><h2>Example</h2>100,100
	  <div class="informalexample"><pre class="programlisting">
open window 200,200
window origin "cc"
circle 0,0,60
          </pre><p>This example draws a circle, centered at the center of the window.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543298"></a><h2>See also</h2><p><code class="function"><a href="#ref_open_window" title="open window">open window</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_x"></a>X</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_xor">xor()</a></span><span class="refpurpose"> - compute the exclusive or</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_xor"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>xor() — compute the exclusive or</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
x=xor(a,b)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543361"></a><h2>Description</h2><p>The <code class="function">xor</code> computes the bitwise <span class="emphasis"><em>exclusive or</em></span> of its two numeric arguments. To understand the result, both arguments should be viewed as binary numbers (i.e. a series of 0 and 1); a bit of the result will then be 1, if exactly one argument has a 1 and the other has a 0 at this position in their binary representation.</p><p>Note, that both arguments are silently converted to integer values and that negative numbers have their own binary representation and may lead to unexpected results when passed to <code class="function">and</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543397"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print xor(7,4)
          </pre><p>This will print <code class="computeroutput">3</code>. This result is obvious, if you note, that the binary representation of 7 and 4 are 111 and 100 respectively; this will yield 011 in binary representation or 2 as decimal.</p><p>The <code class="function">eor</code>-function is the same as the <code class="function">xor</code> function; both are synonymous; however they have each their own description, so you may check out the entry of <code class="function"><a href="#ref_eor" title="eor()">eor</a></code> for a slightly different view.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543453"></a><h2>See also</h2><p><code class="function"><a href="#ref_arithmetic_and" title="and()">and</a></code>, <a href="#ref_arithmetic_or" title="or()"><code class="function">or</code></a>, <a href="#ref_eor" title="eor()"><code class="function">eor</code></a>, <a href="#ref_not" title="not"><code class="function">not</code></a></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_special_characters"></a>Special characters</h3></div></div></div><div class="toc"><dl><dt><span class="refentrytitle"><a href="#ref_hash">#</a></span><span class="refpurpose"> - either a comment or a marker for a file-number</span></dt><dt><span class="refentrytitle"><a href="#ref_double_slash">//</a></span><span class="refpurpose"> - starts a comment</span></dt><dt><span class="refentrytitle"><a href="#ref_at_sign">@</a></span><span class="refpurpose"> - synonymous to at</span></dt><dt><span class="refentrytitle"><a href="#ref_colon">:</a></span><span class="refpurpose"> - separate commands from each other</span></dt><dt><span class="refentrytitle"><a href="#ref_semicolon">;</a></span><span class="refpurpose"> - suppress the implicit newline after a print-statement</span></dt><dt><span class="refentrytitle"><a href="#ref_pow">** or ^</a></span><span class="refpurpose"> - raise its first argument to the power of its second</span></dt></dl></div><div class="refentry" lang="en" xml:lang="en"><a id="ref_hash"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p># — either a comment or a marker for a file-number</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
# This is a comment, but the line below not !
open #1,"foo"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543547"></a><h2>Description</h2><p>The hash ('<code class="literal">#</code>') has two totally unrelated uses:</p><div class="itemizedlist"><ul type="disc"><li><p>A hash might appear in commands related with file-io. <span class="application">yabasic</span> uses simple numbers to refer to open files (within <code class="function"><a href="#ref_input" title="input">input</a></code>, <code class="function"><a href="#ref_print" title="print">print</a></code>, <code class="function"><a href="#ref_peek" title="peek">peek</a></code> or <code class="function"><a href="#ref_eof" title="eof">eof</a></code>). In those commands the hash may precede the number, which species the file. Please see those commands for further information and examples; the rest of <span class="emphasis"><em>this</em></span> entry is about the second use (as a comment).</p></li><li><p>As the <span class="emphasis"><em>very first</em></span> character within a line, a hash introduces comments (similar to <code class="function">rem</code>).</p></li></ul></div><p> '<code class="literal">#</code>' as a comment is common in most scripting languages and has a special use under Unix: If the <span class="emphasis"><em>very first line</em></span> of any Unix-program begins with the character sequence '<code class="literal">#!</code>' ("she-bang", no spaces allowed), the rest of the line is taken as the program that should be used to execute the script. I.e. if your <span class="application">yabasic</span>-program starts with '<code class="literal">#!/usr/local/bin/yabasic</code>', the program <code class="filename">/usr/local/bin/yabasic</code> will be invoked to execute the rest of the program. As a remark for windows-users: This mechanism ensures, that <span class="application">yabasic</span> will be invoked to execute your program; the ending of the file (e.g. <code class="literal">.yab</code>) will be ignored by Unix.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543701"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
# This line is a valid comment
print "Hello " : # But this is a syntax error, because
print "World!" : # the hash is not the first character !
          </pre><p>Note, that this example will produce a syntax error and is <span class="emphasis"><em>not</em></span> a valid program !</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543727"></a><h2>See also</h2><p><code class="function"><a href="#ref_input" title="input">input</a></code>, <code class="function"><a href="#ref_print" title="print">print</a></code>, <code class="function"><a href="#ref_peek" title="peek">peek</a></code> or <code class="function"><a href="#ref_eof" title="eof">eof</a></code>, <code class="function"><a href="#ref_double_slash" title="//">//</a></code>, <code class="function"><a href="#ref_rem" title="rem">rem</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_double_slash"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>// — starts a comment</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
//  This is a comment !
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543828"></a><h2>Description</h2><p>The double-slash ('<code class="literal">//</code>') is (besides <code class="literal">REM</code> and '<code class="literal">#</code>') the third way to start a comment. '<code class="literal">//</code>' is the latest and greatest in the field of commenting and allows <span class="application">yabasic</span> to catch up with such cool languages like C++ and Java.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543870"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
// Another comment.
print "Hello world !" // Another comment
          </pre><p>Unlike the example given for '<code class="literal"><a href="#ref_hash" title="#">#</a></code>' this example is syntactically correct and will not produce an error.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543902"></a><h2>See also</h2><p> <code class="function"><a href="#ref_hash" title="#">#</a></code>, <code class="function"><a href="#ref_rem" title="rem">rem</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_at_sign"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>@ — synonymous to <code class="function"><a href="#ref_at" title="at()">at</a></code></p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
clear screen
…
print @(a,b)
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2543972"></a><h2>Description</h2><p>As '<code class="literal">@</code>' is simply a synonym for <code class="literal">at</code>, please see <code class="function"><a href="#ref_at" title="at()">at</a></code> for further information.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2544004"></a><h2>See also</h2><p><code class="function"><a href="#ref_at" title="at()">at</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_colon"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>: — separate commands from each other</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print "Hello ":print "World"
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2544054"></a><h2>Description</h2><p>The <span class="emphasis"><em>colon</em></span> ('<code class="literal">:</code>') separates multiple commands on a single line.</p><p>The <span class="emphasis"><em>colon</em></span> and the <span class="emphasis"><em>newline</em></span>-character have mostly the same effect, only that the latter, well, starts a new line too. The only other difference is their effect within the (so-called) <span class="emphasis"><em>short</em></span> <code class="function">if</code>, which is an <code class="function">if</code>-statement without the keyword <code class="function">then</code>. Please see the entry for <code class="function"><a href="#ref_if" title="if">if</a></code> for more details.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2544119"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
if (a&lt;10) print "Hello ":print "World !"
          </pre><p>This example demonstrates the difference between colon and newline as described above.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2544141"></a><h2>See also</h2><p><code class="function"><a href="#ref_if" title="if">if</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_semicolon"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>; — suppress the implicit newline after a <code class="function"><a href="#ref_print" title="print">print</a></code>-statement</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print "foo",bar;
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2544203"></a><h2>Description</h2><p>The semicolon ('<code class="literal">;</code>') may only appear at the last position within a <code class="function"><a href="#ref_print" title="print">print</a></code>-statement. It suppresses the implicit newline, which <span class="application">yabasic</span> normally adds after each <code class="function">print</code>-statement.</p><p>Put another way: Normally the output of each <code class="function">print</code>-statement appears on a line by itself. If you rather want the output of many <code class="function">print</code>-statements to appear on a single line, you should end the <code class="function">print</code>-statement with a semicolon.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2544267"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print "Hello ";:print "World !"
          </pre><p>This example prints <code class="computeroutput">Hello World !</code> <span class="emphasis"><em>in a single line</em></span>.</p></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2544297"></a><h2>See also</h2><p><code class="function"><a href="#ref_print" title="print">print</a></code></p></div></div><div class="refentry" lang="en" xml:lang="en"><div class="refentry.separator"><hr /></div><a id="ref_pow"></a><div class="titlepage"></div><div class="refnamediv"><h2>Name</h2><p>** or ^ — raise its first argument to the power of its second</p></div><div class="refsynopsisdiv"><h2>Synopsis</h2><pre class="synopsis">
print 2**b
print 3^4
</pre></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2544348"></a><h2>Description</h2><p><code class="function">**</code> (or <code class="function">^</code>, which is an
exact synonym), is the arithmetic operator of exponentiation; it requires one
number to its left and a second one to its right; <code class="function">**</code> then
raises the first argument to the power of the second and returns the
result. The result will only be computed if it yields a <span class="emphasis"><em>real</em></span> number (as opposed to a <span class="emphasis"><em>complex</em></span> number); this means, that the power can <span class="emphasis"><em>not</em></span> be computed, if the first argument is negative and the second one is fractional. On the other hand, the second argument can be fractional, if the first one ist positive; this means, that <code class="function">**</code> may be used to compute arbitrary roots: e.g. <code class="function">x**0.5</code> computes the square root of <code class="function">x</code>.</p></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2544412"></a><h2>Example</h2><div class="informalexample"><pre class="programlisting">
print 2**0.5
          </pre></div></div><div class="refsect1" lang="en" xml:lang="en"><a id="id2544428"></a><h2>See also</h2><p><code class="function"><a href="#ref_sqrt" title="sqrt()">sqrt</a></code></p></div></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="reserved_word"></a>Reserved Words</h3></div></div></div><p>Here is a list of all reserved words in
<span class="application">yabasic</span>. Please make sure, that you do not try to
use one of them as the name of a variable or subroutine. Or, the other way
around: If you get some mysterious error from <span class="application">yabasic</span>
and you just can't figure out why, then you might be using one of the reserved words
below, without knowing.
</p><p>Anyway, here is the list:</p><div class="informaltable"><table border="0"><colgroup><col /><col /><col /><col /><col /></colgroup><tbody><tr><td><code class="function">ABS</code></td><td><code class="function">ACOS</code></td><td><code class="function">AND</code></td><td><code class="function">ARRAYDIM</code></td><td><code class="function">ARRAYDIMENSION</code></td></tr><tr><td><code class="function">ARRAYSIZE</code></td><td><code class="function">AS</code></td><td><code class="function">ASC</code></td><td><code class="function">ASIN</code></td><td><code class="function">AT</code></td></tr><tr><td><code class="function">ATAN</code></td><td><code class="function">BEEP</code></td><td><code class="function">BELL</code></td><td><code class="function">BIN$</code></td><td><code class="function">BIND</code></td></tr><tr><td><code class="function">BITBLIT</code></td><td><code class="function">BITBLIT$</code></td><td><code class="function">BITBLT</code></td><td><code class="function">BITBLT$</code></td><td><code class="function">BOX</code></td></tr><tr><td><code class="function">BREAK</code></td><td><code class="function">CASE</code></td><td><code class="function">CHR$</code></td><td><code class="function">CIRCLE</code></td><td><code class="function">CLEAR</code></td></tr><tr><td><code class="function">CLOSE</code></td><td><code class="function">COLOR</code></td><td><code class="function">COLOUR</code></td><td><code class="function">COMPILE</code></td><td><code class="function">CONTINUE</code></td></tr><tr><td><code class="function">COS</code></td><td><code class="function">CURVE</code></td><td><code class="function">DATA</code></td><td><code class="function">DATE$</code></td><td><code class="function">DEC</code></td></tr><tr><td><code class="function">DEFAULT</code></td><td><code class="function">DIM</code></td><td><code class="function">DO</code></td><td><code class="function">DOT</code></td><td><code class="function">ELSE</code></td></tr><tr><td><code class="function">ELSEIF</code></td><td><code class="function">ELSIF</code></td><td><code class="function">END</code></td><td><code class="function">ENDIF</code></td><td><code class="function">EOF</code></td></tr><tr><td><code class="function">EOR</code></td><td><code class="function">ERROR</code></td><td><code class="function">EXECUTE</code></td><td><code class="function">EXECUTE$</code></td><td><code class="function">EXIT</code></td></tr><tr><td><code class="function">EXP</code></td><td><code class="function">EXPORT</code></td><td><code class="function">FI</code></td><td><code class="function">FILL</code></td><td><code class="function">FILLED</code></td></tr><tr><td><code class="function">FOR</code></td><td><code class="function">FRAC</code></td><td><code class="function">GETBIT$</code></td><td><code class="function">GETSCREEN$</code></td><td><code class="function">GLOB</code></td></tr><tr><td><code class="function">GOSUB</code></td><td><code class="function">GOTO</code></td><td><code class="function">HEX$</code></td><td><code class="function">IF</code></td><td><code class="function">INKEY$</code></td></tr><tr><td><code class="function">INPUT</code></td><td><code class="function">INSTR</code></td><td><code class="function">INT</code></td><td><code class="function">INTERRUPT</code></td><td><code class="function">LABEL</code></td></tr><tr><td><code class="function">LEFT$</code></td><td><code class="function">LEN</code></td><td><code class="function">LET</code></td><td><code class="function">LINE</code></td><td><code class="function">LOCAL</code></td></tr><tr><td><code class="function">LOG</code></td><td><code class="function">LOOP</code></td><td><code class="function">LOWER$</code></td><td><code class="function">LTRIM$</code></td><td><code class="function">MAX</code></td></tr><tr><td><code class="function">MID$</code></td><td><code class="function">MIN</code></td><td><code class="function">MOD</code></td><td><code class="function">MOUSEB</code></td><td><code class="function">MOUSEBUTTON</code></td></tr><tr><td><code class="function">MOUSEMOD</code></td><td><code class="function">MOUSEMODIFIER</code></td><td><code class="function">MOUSEX</code></td><td><code class="function">MOUSEY</code></td><td><code class="function">NEW</code></td></tr><tr><td><code class="function">NEXT</code></td><td><code class="function">NOT</code></td><td><code class="function">NUMPARAM</code></td><td><code class="function">ON</code></td><td><code class="function">OPEN</code></td></tr><tr><td><code class="function">OR</code></td><td><code class="function">ORIGIN</code></td><td><code class="function">PAUSE</code></td><td><code class="function">PEEK</code></td><td><code class="function">PEEK$</code></td></tr><tr><td><code class="function">POKE</code></td><td><code class="function">PRINT</code></td><td><code class="function">PRINTER</code></td><td><code class="function">PUTBIT</code></td><td><code class="function">PUTSCREEN</code></td></tr><tr><td><code class="function">RAN</code></td><td><code class="function">READ</code></td><td><code class="function">READING</code></td><td><code class="function">RECT</code></td><td><code class="function">RECTANGLE</code></td></tr><tr><td><code class="function">REDIM</code></td><td><code class="function">REPEAT</code></td><td><code class="function">RESTORE</code></td><td><code class="function">RETURN</code></td><td><code class="function">REVERSE</code></td></tr><tr><td><code class="function">RIGHT$</code></td><td><code class="function">RINSTR</code></td><td><code class="function">RTRIM$</code></td><td><code class="function">SCREEN</code></td><td><code class="function">SEEK</code></td></tr><tr><td><code class="function">SIG</code></td><td><code class="function">SIN</code></td><td><code class="function">SLEEP</code></td><td><code class="function">SPLIT</code></td><td><code class="function">SPLIT$</code></td></tr><tr><td><code class="function">SQR</code></td><td><code class="function">SQRT</code></td><td><code class="function">STATIC</code></td><td><code class="function">STEP</code></td><td><code class="function">STR$</code></td></tr><tr><td><code class="function">SUB</code></td><td><code class="function">SUBROUTINE</code></td><td><code class="function">SWITCH</code></td><td><code class="function">SYSTEM</code></td><td><code class="function">SYSTEM$</code></td></tr><tr><td><code class="function">TAN</code></td><td><code class="function">TELL</code></td><td><code class="function">TEXT</code></td><td><code class="function">THEN</code></td><td><code class="function">TIME$</code></td></tr><tr><td><code class="function">TO</code></td><td><code class="function">TOKEN</code></td><td><code class="function">TOKEN$</code></td><td><code class="function">TRIANGLE</code></td><td><code class="function">TRIM$</code></td></tr><tr><td><code class="function">UNTIL</code></td><td><code class="function">UPPER$</code></td><td><code class="function">USING</code></td><td><code class="function">VAL</code></td><td><code class="function">WAIT</code></td></tr><tr><td><code class="function">WEND</code></td><td><code class="function">WHILE</code></td><td><code class="function">WINDOW</code></td><td><code class="function">WRITING</code></td><td><code class="function">XOR</code></td></tr></tbody></table></div><p>
Please see <a href="#chapter_ref_words" title="Chapter&#xA0;6.&#xA0;All commands and functions of yabasic grouped alphabetically">here</a> for explanations on
how to use these words in <span class="application">yabasic</span>.
</p></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="chapter_ref_concepts"></a>Chapter 7. A grab-bag of some general concepts and terms</h2></div></div></div><div class="toc"><dl><dt><span class="sect1"><a href="#ref_logical_shortcuts">Logical shortcuts</a></span></dt><dt><span class="sect1"><a href="#ref_conditions_and_expressions">Conditions and expressions</a></span></dt><dt><span class="sect1"><a href="#ref_array_references">References on arrays</a></span></dt><dt><span class="sect1"><a href="#ref_windows_filenames">Specifying Filenames under Windows</a></span></dt><dt><span class="sect1"><a href="#ref_escape_sequences">Escape-sequences</a></span></dt><dt><span class="sect1"><a href="#ref_standalone">Creating a <span class="emphasis"><em>standalone</em></span> program from your yabasic-program</a></span></dt></dl></div><p>This chapter presents some general concepts and terms, which deserve a description on their own, but are not associated with a single command or function in <span class="application">yabasic</span>. Most of these topics do not lend themselves to be read alone, rather they might be read (or skimmed) as background material if an entry from the <a href="#chapter_ref_words" title="Chapter&#xA0;6.&#xA0;All commands and functions of yabasic grouped alphabetically">alphabetical list of commands</a> refers to them.</p><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_logical_shortcuts"></a>Logical shortcuts</h3></div></div></div><p><span class="emphasis"><em>Logical shortcuts</em></span> are no special language construct and there is no keyword for them; they are just a way to evaluate <span class="emphasis"><em>logical expressions</em></span>. Logical expressions (i.e. a series of conditions or comparisons joined by <a href="#ref_arithmetic_and" title="and()"><code class="function">and</code></a> or <a href="#ref_arithmetic_or" title="or()"><code class="function">or</code></a>) are only evaluated until the final result of the expression can be determined. An example:</p><div class="informalexample"><pre class="programlisting">
if (a&lt;&gt;0 and b/a&gt;2) print "b is at least twice as big as a"
</pre></div><p>
      The logical expression <code class="literal">a&lt;&gt;0 and b/a&gt;2</code> consists of two comparisons, both of which must be true, if the <code class="function">print</code> statement should be executed. Now, if the first comparison (<code class="literal">a&lt;&gt;0</code>) is <code class="constant">false</code>, the whole logical expression can never be <code class="constant">true</code> and the second comparison (<code class="literal">b/a&gt;2</code>) need not be evaluated.
      </p><p>This is exactly, how <span class="application">yabasic</span> behaves: The evaluation of a composed logical expressions is terminated immediately, as soon as the final result can be deduced from the already evaluated parts.</p><p>In practice, this has the following consequences:</p><div class="itemizedlist"><ul type="disc"><li><p>If two or more comparisons are joined with <code class="function">and</code> and one comparison results in <code class="constant">false</code>, the logical expression is evaluated no further and the overall result is <code class="constant">false</code>.</p></li><li><p>If two or more comparisons are joined with <code class="function">or</code> and one comparison results in <code class="constant">true</code>, the logical expression is evaluated no further and the result is <code class="constant">true</code>.</p></li></ul></div><p><span class="quote">Nice, but whats this good for ?</span>”, I hear you say. Well, just have another look at the example, especially the second comparison (<code class="literal">b/a&gt;2</code>); dividing <code class="literal">b</code> by <code class="literal">a</code> is potentially hazardous: If <code class="literal">a</code> equals zero, the expression will cause an error and your program will terminate. To avoid this, the first part of the comparison (<code class="literal">a&lt;&gt;0</code>) checks, if the second one can be evaluated without risk. This pre-checking is the most common usage and primary motivation for <span class="emphasis"><em>logical shortcuts</em></span> (and the reason why most programming languages implement them).</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_conditions_and_expressions"></a>Conditions and expressions</h3></div></div></div><p>Well, bottomline there is no difference or distinction between <span class="emphasis"><em>conditions</em></span> and <span class="emphasis"><em>expressions</em></span>, at least as <span class="application">yabasic</span> is concerned. So you may assign the result of comparisons to variables or use an arithmetic expression or a simple variable within a condition (e.g. within an <code class="function">if</code>-statement). So the constructs shown in the example below are all totally valid:</p><div class="informalexample"><pre class="programlisting">
input "Please enter a number between 1 and 10: " a

rem   Assigning the result of a comparison to a variable
okay=a&gt;=1 and a&lt;=10

rem   Use a variable within an if-statement
if (not okay) error "Wrong, wrong !"
</pre></div><p>So conditions and expressions are really the same thing (at least as long as yabasic is concerned). Therefore the terms <em class="wordasword">conditions</em> and <em class="wordasword">expression</em> can really be used interchangeably, at least in theory. In reality the term <em class="wordasword">condition</em> is used in connection with <code class="function">if</code> or <code class="function">while</code> whereas the term <em class="wordasword">expression</em> tends to be used more often within arithmetic context.</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_array_references"></a>References on arrays</h3></div></div></div><p><span class="emphasis"><em>References on arrays</em></span> are the only way to refer to an array <span class="emphasis"><em>as a whole</em></span> and to pass it to subroutines or functions like <a href="#ref_arraydim" title="arraydim()"><code class="function">arraydim</code></a> or <a href="#ref_arraysize" title="arraysize()"><code class="function">arraysize</code></a>. Whereas (for example) <code class="literal">a(2)</code> designates the second element of the array <code class="literal">a</code>, <code class="literal">a()</code> (with empty braces) refers to the array <code class="literal">a</code> itself. <code class="literal">a()</code> is called an <span class="emphasis"><em>array reference</em></span>.</p><p>If you pass an array reference to one of your own subroutines, you need to be aware, that the subroutine will be able to modify the array you have passed in. So passing an array reference does not create a copy of the array; this has some interesting consequences:</p><div class="itemizedlist"><ul type="disc"><li><p><span class="emphasis"><em>Speed and space:</em></span> Creating a copy of an
array would be a time (and resource) consuming operation; passing just a reference is cheap and fast.</p></li><li><p>Returning many values: A subroutine, that wants to give back more than one value, may require an array reference among its arguments and then store its many return values within this array. This is the only way to return more than one value from a subroutine.</p></li></ul></div></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_windows_filenames"></a>Specifying Filenames under Windows</h3></div></div></div><p>As you probably know, windows uses the character '<code class="literal">\</code>' to separate the directories within a pathname; an example would be <code class="literal">C:\yabasic\yabasic.exe</code> (the usual location of the <span class="application">yabasic</span> executable). However, the very same character '<code class="literal">\</code>' is used to construct <a href="#ref_escape_sequences" title="Escape-sequences">escape sequences</a>, not only in <span class="application">yabasic</span> but in most other programming languages.</p><p>Therefore the string <code class="literal">"C:\t.dat"</code> does <span class="emphasis"><em>not</em></span> specify the file <code class="literal">t.dat</code> within the directory <code class="literal">C:</code>; this is because the sequence '<code class="literal">\t</code>' is translated into the tab-character. To specify this filename, you need to use the string <code class="literal">"C:\\t.dat"</code> (note the double slash '<code class="literal">\\</code>').</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_escape_sequences"></a>Escape-sequences</h3></div></div></div><p><span class="emphasis"><em>Escape-sequences</em></span> are the preferred way of specifying 'special' characters. They are introduced by the '\'-character and followed by one of a few regular letters, e.g. '\n' or '\r' (see the table below).</p><p>Escape-sequences may occur within any string at any position; they are replaced at <span class="emphasis"><em>parsetime</em></span> (opposed to <span class="emphasis"><em>runtime</em></span>), i.e. as soon as <span class="application">yabasic</span> discovers the string, with their corresponding <span class="emphasis"><em>special</em></span> character. As a consequence of this <code class="function">len("\a")</code> returns 1, because <span class="application">yabasic</span> replaces <code class="function">"\a"</code> with the matching special character just before the program executes.</p><div class="table"><a id="id2546274"></a><p class="title"><b>Table 7.1. Escape sequences</b></p><table summary="Escape sequences" border="1"><colgroup><col /><col /></colgroup><thead><tr><th>Escape Sequence</th><th>Matching special character</th></tr></thead><tbody><tr><td><code class="computeroutput">\n</code></td><td><span class="emphasis"><em>newline</em></span></td></tr><tr><td><code class="computeroutput">\t</code></td><td><span class="emphasis"><em>tabulator</em></span></td></tr><tr><td><code class="computeroutput">\v</code></td><td><span class="emphasis"><em>vertical tabulator</em></span></td></tr><tr><td><code class="computeroutput">\b</code></td><td><span class="emphasis"><em>backspace</em></span></td></tr><tr><td><code class="computeroutput">\r</code></td><td><span class="emphasis"><em>carriage return</em></span></td></tr><tr><td><code class="computeroutput">\f</code></td><td><span class="emphasis"><em>formfeed</em></span></td></tr><tr><td><code class="computeroutput">\a</code></td><td><span class="emphasis"><em>alert</em></span> (i.e. a beeping sound)</td></tr><tr><td><code class="computeroutput">\\</code></td><td><span class="emphasis"><em>backslash</em></span></td></tr><tr><td><code class="computeroutput">\'</code></td><td><span class="emphasis"><em>single quote</em></span></td></tr><tr><td><code class="computeroutput">\"</code></td><td><span class="emphasis"><em>double quote</em></span></td></tr><tr><td><code class="computeroutput">\x</code><span class="emphasis"><em>HEX</em></span></td><td><code class="function">chr$(</code><span class="emphasis"><em>HEX</em></span><code class="function">)</code> (see below)</td></tr></tbody></table></div><p>Note, that an escape sequences of the form \xHEX allows to encode arbitrary
     characters as long as you know their position (as a hex-number) within the 
     <span class="acronym">ascii</span>-charset: 
     For example \x012 is transformed into the character <code class="function">chr$(18)</code> (or <code class="function">chr$(dec("12",16))</code>. Note that \x requires a
     hexa-decimal number (and the hexa-decimal string "12" corresponds to the decimal number 18).</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h3 class="title"><a id="ref_standalone"></a>Creating a <span class="emphasis"><em>standalone</em></span> program from your yabasic-program</h3></div></div></div><div class="toc"><dl><dt><span class="sect3"><a href="#id2546689">Creating a standalone-program from the commandline</a></span></dt><dt><span class="sect3"><a href="#id2546870">Creating a standalone-program from within your program</a></span></dt><dt><span class="sect3"><a href="#id2547061">Downsides of creating a standalone program</a></span></dt><dt><span class="sect3"><a href="#id2547137">See also</a></span></dt></dl></div><div class="note" style="margin-left: 0.5in; margin-right: 0.5in;"><h3 class="title">Note</h3><p>The <code class="function">bind</code>-feature, which is described below, is at an experimental stage right now. It works (at least for me !) under Windows and Linux, but I cannot even promise it for other variants of Unix. However, if it does not work for your Unix, I will at least try to make it work, if you give me sufficient information of your system.</p></div><p>Sometimes you may want to give one of your yabasic-programs to other people. However, what if those other people do not have <span class="application">yabasic</span> installed ? In that case you may create a <span class="emphasis"><em>standalone</em></span>-program from your yabasic-program, i.e. an executable, that may be executed on its own, standalone, even (and especially !) on computers, that do not have <span class="application">yabasic</span> installed. Having created a standalone program, you may pass it around like any other program (e.g. one written in <span class="application">C</span>) and you can be sure that your program will execute right away.</p><p>Such a standalone-program is simply created by copying the full <span class="application">yabasic</span>-interpreter and your yabasic-program (plus all the libraries it does <code class="function">import</code>) together into a single, new program, whose name might be chosen at will (under windows of course it should have the ending <code class="filename">.exe</code>). If you decide to create a standalone-program, there are three bits in yabasic, that you may use:</p><div class="itemizedlist"><ul type="disc"><li><p>The <code class="function"><a href="#ref_bind" title="bind()">bind</a></code>-command, which does the actual job of creating the standalone program from the <span class="application">yabasic</span>-interpreter and your program.</p></li><li><p>The command-line Option <code class="literal">-bind</code> (available under <a href="#windows_options">windows</a> and <a href="#unix_options">Unix</a>), which does the same from the command-line.</p></li><li><p>The special <code class="function"><a href="#ref_peek" title="peek">peek("isbound")</a></code>, which may be used to check, if the <span class="application">yabasic</span>-program containing this <code class="function">peek</code> is bound to the interpreter as part of a standalone program.</p></li></ul></div><p>With these bits you know enough to create a standalone-program. Actually there are two ways to do this: on the commandline and from within your program.</p><div class="sect3" lang="en" xml:lang="en"><div class="titlepage"><div><div><h4 class="title"><a id="id2546689"></a>Creating a standalone-program from the commandline</h4></div></div></div><p>Let's say you have the following <span class="emphasis"><em>very</em></span> simple program within the file <code class="filename">foo.yab</code>:</p><div class="informalexample"><pre class="programlisting">
print "Hello World !"
</pre></div><p>Normally you would start this <span class="application">yabasic</span>-program by typing <strong class="userinput"><code>yabasic foo.yab</code></strong> and as a result the string <code class="computeroutput">Hello World !</code> would appear on your screen. However, to create a <span class="emphasis"><em>standalone</em></span>-program from <code class="filename">foo.yab</code> you would type:</p><div class="informalexample"><p><strong class="userinput"><code>yabasic -bind foo.exe foo.yab</code></strong></p></div><p>This command does <span class="emphasis"><em>not</em></span> execute your program <code class="filename">foo.yab</code> but rather create a <span class="emphasis"><em>standalone</em></span>-program <code class="filename">foo.exe</code>. Note: under Unix you would probably name the standalone program <code class="filename">foo</code> or such, omitting the windows-specific ending <code class="filename">.exe</code>. </p><p><span class="application">Yabasic</span> will confirm by printing something like: <code class="computeroutput">---Info: Successfully bound 'yabasic' and 'foo.yab' into 'foo.exe'</code>.</p><p>After that you will find a program <code class="filename">foo.exe</code> (which must be made <span class="emphasis"><em>executable</em></span> with the <span><strong class="command">chmod</strong></span>-command under Unix first). Now, executing this program <code class="filename">foo.exe</code> (or <code class="filename">foo</code> under Unix) will produce the output <code class="computeroutput">Hello World !</code>.</p><p>This newly created program <code class="filename">foo.exe</code> might be passed around to anyone, even if he does not have <span class="application">yabasic</span> installed.</p></div><div class="sect3" lang="en" xml:lang="en"><div class="titlepage"><div><div><h4 class="title"><a id="id2546870"></a>Creating a standalone-program from within your program</h4></div></div></div><p>It is possible to write a <span class="application">yabasic</span>-program, that binds itself to the <span class="application">yabasic</span>-interpreter. Here is an example:</p><div class="informalexample"><pre class="programlisting">
if (!peek("isbound")) then
  bind "foo"
  print "Successfully created the standalone executable 'foo' !"
  exit
endif

print "Hello World !"
</pre></div><p>If you run this program (which may be saved in the file <code class="filename">foo.yab</code>) via <strong class="userinput"><code>yabasic foo.yab</code></strong>, the <code class="function"><a href="#ref_peek" title="peek">peek("isbound")</a></code> in the first line will check, if the program is already part of a standalone-program. If <span class="emphasis"><em>not</em></span> (i.e. if the <span class="application">yabasic</span>-interpreter and the <span class="application">yabasic</span>-program are separate files) the <code class="function"><a href="#ref_bind" title="bind()">bind</a></code>-command will create a standalone program <code class="filename">foo</code> containing both. As a result you would see the output <code class="computeroutput">Successfully created the standalone executable 'foo' !</code>. Note: Under Windows you would probably choose the filename <code class="filename">foo.exe</code>.</p><p>Now, if you run this standalone executable <code class="filename">foo</code> (or <code class="filename">foo.exe</code>), the very same <span class="application">yabasic</span>-program that is shown above will be executed again. However, this time the <code class="function"><a href="#ref_peek" title="peek">peek("isbound")</a></code> will return <code class="constant">TRUE</code> and therefore the condition of the <code class="function">if</code>-statement is <span class="emphasis"><em>false</em></span> and the three lines after <code class="function">then</code> are <span class="emphasis"><em>not</em></span> executed. Rather the last <code class="function">print</code>-statement will run, and you will see the output <code class="computeroutput">Hello World !</code>.</p><p>That way a <span class="application">yabasic</span>-program may turn itself into a standalone-program.</p></div><div class="sect3" lang="en" xml:lang="en"><div class="titlepage"><div><div><h4 class="title"><a id="id2547061"></a>Downsides of creating a standalone program</h4></div></div></div><p>Now, before you go out and turn all your <span class="application">yabasic</span>-programs into standalone programs, please take a second to consider the downsides of doing so:</p><div class="itemizedlist"><ul type="disc"><li><p>The new standalone program will be at least as big as the interpreter itself, so you need to pass a few hundred kilobytes around, just to save people from having to install <span class="application">yabasic</span> themselves.</p></li><li><p>There is no easy way to extract your <span class="application">yabasic</span>-program from within the standalone program: If you ever want to change it, you need to have it around separately.</p></li><li><p>If a new version of <span class="application">yabasic</span> becomes available, again you need to recreate all of your standalone programs to take advantage of bugfixes and improvements.</p></li></ul></div><p>So, being able to create a standalone program is certainly a good thing, but certainly <span class="emphasis"><em>not</em></span> a silver bullet.</p></div><div class="sect3" lang="en" xml:lang="en"><div class="titlepage"><div><div><h4 class="title"><a id="id2547137"></a>See also</h4></div></div></div><p>The <a href="#ref_bind" title="bind()"><code class="function">bind</code></a>-command, the <a href="#ref_peek" title="peek"><code class="function">peek</code></a>-function and the commandline options for <a href="#unix_options">Unix</a> and <a href="#windows_options">Windows</a>.</p></div></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="chapter_examples"></a>Chapter 8. A few example programs</h2></div></div></div><div class="toc"><dl><dt><span class="sect1"><a href="#id2547195">A very simple program</a></span></dt><dt><span class="sect1"><a href="#id2547219">The demo of yabasic</a></span></dt></dl></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2547195"></a>A very simple program</h2></div></div></div><p>The program below is a very simple program:</p><pre class="programlisting">
repeat
  input "Please enter the first number, to add " a
  input "Please enter the second number, to add " b
  print a+b
until(a=0 and b=0)
</pre><p>This program requests two numbers, which it than adds. The process is repeated until you enter zero (or nothing) twice.</p></div><div class="sect1" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title" style="clear: both"><a id="id2547219"></a>The demo of yabasic</h2></div></div></div><p>The listing below is the <span class="emphasis"><em>demo</em></span> of yabasic. Note, that parts of this demo have been written <span class="emphasis"><em>before</em></span> some of the more advanced features (e.g <span class="emphasis"><em>subroutines</em></span>) of <span class="application">yabasic</span> have been implemented. So please do not take this as a particular good example of <span class="application">yabasic</span>-code.</p><pre class="programlisting">
//
//      This program demos yabasic
//


//      Check, if screen is large enough
clear screen
sw=peek("screenwidth"):sh=peek("screenheight")
if (sw&lt;78 or sh&lt;24) then
  print
  print "  Sorry, but your screen is to small to run this demo !"
  print
  end
endif
sw=78:sh=24

//  Initialize everything
restore mmdata
read mmnum:dim mmtext$(mmnum)
for a=1 to mmnum:read mmtext$(a):next a

//  Main loop selection of demo
ysel=1
label mainloop
clear screen
print colour("cyan","magenta") at(7,2) "################################"
print colour("cyan","magenta") at(7,3) "################################"
print colour("cyan","magenta") at(7,4) "################################"
print colour("yellow","blue") at(8,3) " This is the demo for yabasic "
yoff=7
for a=1 to mmnum
  if (a=mmnum) then ydisp=1:else ydisp=0:fi
  if (a=ysel) then
    print colour("blue","green") at(5,yoff+ydisp+a) mmtext$(a);
  else
    print at(5,yoff+ydisp+a) mmtext$(a);
  endif
next a
print at(3,sh-3) "Move selection with CURSOR KEYS (or u and d),"
print at(3,sh-2) "Press RETURN or SPACE to choose, ESC to quit."


do    // loop for keys pressed
  rev=1
  do    // loop for blinking
    k$=inkey$(0.4)
    if (k$="") then
      if (ysel=mmnum) then
        if (rev=1) then 
          print colour("blue","green") at(5,yoff+mmnum+1) mmtext$(mmnum);
          rev=0
        else
          print colour("yellow","red") at(5,yoff+mmnum+1) mmtext$(mmnum);
          rev=1
        endif
      endif
    else    // key has been pressed, leave loop
      break
    endif
  loop    // loop for blinking

  yalt=ysel
  if (k$="up" or k$="u") then 
    if (ysel=1) then ysel=mmnum else ysel=ysel-1 fi
    redraw():heal():continue
  fi
  if (k$="down" or k$="d") then 
    if (ysel=mmnum) then ysel=1 else ysel=ysel+1 fi
    redraw():heal():continue
  fi
  if (k$=" " or k$="enter" or k$="right") then 
    on ysel gosub overview,bitmap,tetraeder,endit
    goto mainloop
  fi
  if (k$="esc") then
    endit()
  fi
  beep
  print at(3,sh-5) "Invalid key: ",k$,"         "
loop    // loop for keys pressed


//  redraw line
sub redraw()
  if (yalt=mmnum) then ydisp=1:else ydisp=0:fi
  print at(5,yoff+yalt+ydisp) mmtext$(yalt);
  if (ysel=mmnum) then ydisp=1:else ydisp=0:fi
  print colour("blue","green") at(5,yoff+ysel+ydisp) mmtext$(ysel);
  return
end sub


//  erase a line
sub heal()
  print at(3,sh-5) "                                                       "
  return
end sub


//  Go here to exit
label endit
  print at(3,sh-8) "Hope you liked it ...\n   ";
  exit
return


//  Present a short overview
label overview
  clear screen
  print
  print "  Yabasic is a quite traditional basic: It comes with"
  print "  print, input, for-next-loops, goto, gosub, while and"
  print "  repeat. It has user defined procedures and libraries,"
  print "  however, it is not object oriented.\n"
  print "  Yabasic makes it easy to open a window, draw lines"
  print "  and print the resulting picture.\n"
  print "  Yabasic programs are interpreted and run under Unix"
  print "  and Windows. The Yabasic interpreter (around 200K)"
  print "  and any Yabasic program can be glued together to"
  print "  form a standalone executable.\n" 
  print "  Yabasic is free software, i.e. subject to the"
  print "  GNU copyright.\n"
  print "\n\n\n  While you read this, I am calculating prime numbers,\n"
  print "  Press any key to return to main menu ..."
  can=1
  print at(6,17) "This is a prime number: "
  label nextcan
  can=can+2
  for i=2 to sqrt(can):if (frac(can/i)=0) then goto notprime:fi:next i
  print at(32,17) can;
  label notprime
  if (lower$(inkey$(0))&lt;&gt;"") then 
    print at(10,sh) "Wrapping around once ...";
    for x=1 to sw
      a$=getscreen$(0,0,1,sh-2)
      b$=getscreen$(1,0,sw-1,sh-2)
      putscreen b$,0,0
      putscreen a$,sw-1,0
    next x
    sleep 2
    return
  fi
goto nextcan


//  Show some animated bitmaps
label bitmap
  clear screen
  print 
  print "Yabasic offers some commands for drawing simple graphics."
  print reverse at(5,12) " Press any key to return to main menu ... "

  n=20
  open window 400,400

  for b=20 to 0 step -1
    color 255-b*12,0,b*12
    fill circle 200,200,b
  next b
  c$=getbit$(179,179,221,221)
  for a=1 to 2000
    color ran(255),ran(255),ran(255)
    x=ran(500)-100:y=ran(500)-100
    fill rectangle ran(500)-100,ran(500)-100,ran(500)-100,ran(500)-100
  next a

  x=200:y=200:phi=ran(2*pi):dx=2*sin(phi):dy=2*cos(phi)
  o$=""
  count=0
  label pong
    count=count+1
    if (o$&lt;&gt;"") putbit o$,xo-2,yo-2
    if (count&gt;1000) then
      phi=ran(2*pi):dx=2*sin(phi):dy=2*cos(phi)
      sleep 2
      count=0
    endif
    xo=x:yo=y
    x=x+dx:y=y+dy
    o$=getbit$(x-2,y-2,x+46,y+46)
    putbit c$,x,y,"t"
    if (x&lt;0 or x&gt;360) dx=-dx
    if (y&lt;0 or y&gt;360) dy=-dy
    if (inkey$(0)&lt;&gt;"") then
      close window
      return
    endif
  goto pong
return

label tetraeder

open window 400,400
clear window
clear screen
print reverse at(5,12) " Press any key to return to main menu ... "	

dim opoints(4,3)
restore points
for n=1 to 4:for p=1 to 3:read opoints(n,p):next p:next n

dim triangles(4,3)
restore triangles
for n=1 to 4:for p=1 to 3:read triangles(n,p):next p:next n

phi=0:dphi=0.1:psi=0:dpsi=0.05
dim points(4,3)

r=60:g=20
dr=0.5:dg=1.2:db=3
label main

  phi=phi+dphi
  psi=psi+dpsi
  for n=1 to 4
    points(n,1)=opoints(n,1)*cos(phi)-opoints(n,2)*sin(phi)
    points(n,2)=opoints(n,2)*cos(phi)+opoints(n,1)*sin(phi)
    p2=          points(n,2)*cos(psi)-opoints(n,3)*sin(psi)
    points(n,3)=opoints(n,3)*cos(psi)+ points(n,2)*sin(psi)
    points(n,2)=p2
  next n

  r=r+dr:if (r&lt;0 or r&gt;60) dr=-dr
  g=g+dg:if (g&lt;0 or g&gt;60) dg=-dg
  b=b+db:if (b&lt;0 or b&gt;60) db=-db
  dm=dm+0.01
  m=120-80*sin(dm)
  for n=1 to 4
    p1=triangles(n,1)
    p2=triangles(n,2)
    p3=triangles(n,3)
    n1=points(p1,1)+points(p2,1)+points(p3,1)
    n2=points(p1,2)+points(p2,2)+points(p3,2)
    n3=points(p1,3)+points(p2,3)+points(p3,3)
    if (n3&gt;0) then
      sp=n1*0.5-n2*0.7-n3*0.6
      color 60+r+30*sp,60+g+30*sp,60+b+30*sp
      fill triangle 200+m*points(p1,1),200+m*points(p1,2),200+m*points(p2,1),200+m*points(p2,2),200+m*points(p3,1),200+m*points(p3,2)
    endif
  next n
  if (inkey$(0.1)&lt;&gt;"") close window:return
  clear window
goto main

label points
data  -1,-1,+1,  +1,-1,-1,  +1,+1,+1,  -1,+1,-1
label triangles
data  1,2,4,  2,3,4,  1,3,4,  1,2,3

//  Data section ...
label mmdata
//  Data for main menu: Number and text of entries in main menu
data 4
data "   Yabasic in a nutshell   "
data "   Some graphics           "
data "   A rotating Tetraeder    "
data "   Exit this demo          "

   </pre></div></div><div class="chapter" lang="en" xml:lang="en"><div class="titlepage"><div><div><h2 class="title"><a id="chapter_copyright"></a>Chapter 9. The Copyright of <span class="application">yabasic</span></h2></div></div></div><p><span class="application">yabasic</span> may be copied only under the terms of the <span class="emphasis"><em><a href="http://www.yabasic.de/artistic.htm" target="_top">Artistic License</a></em></span> or the <span class="emphasis"><em><a href="http://www.yabasic.de/gpl.htm" target="_top">GNU General Public License</a></em></span> (GPL), both of which are distributed with <span class="application">yabasic</span>.</p><p>[<span class="citation">Can't you make up your mind ?!</span>], I hear you say. Umm, well <span class="emphasis"><em>yes</em></span>. In fact I do not want to read or try to understand them both, so I have put the burden on <span class="emphasis"><em>you</em></span> (grin). However, I think that the Artistic License is more liberal and gives you more rights and you should choose it; on the other hand the GPL is more widely known and a lot of software is distributed under its terms.</p><p>Here is a list of things that are possible under the terms of the Artistic License:</p><div class="itemizedlist"><ul type="disc"><li><p>Put <span class="application">yabasic</span> on your own homepage or CD and even charge for the service of distributing <span class="application">yabasic</span>.</p></li><li><p>Write your own <span class="application">yabasic</span>-programs, pack your program and <span class="application">yabasic</span> into a package and sell the whole thing.</p></li><li><p>Modify <span class="application">yabasic</span> and add or remove features, sell the modified version.</p></li></ul></div></div></div></body></html>


syntax highlighted by Code2HTML, v. 0.9.1