168 lines
9.7 KiB
HTML
168 lines
9.7 KiB
HTML
<?xml version="1.0" encoding="utf-8"?>
|
|
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
|
|
<html xmlns:MadCap="http://www.madcapsoftware.com/Schemas/MadCap.xsd" MadCap:lastBlockDepth="6" MadCap:lastHeight="94" MadCap:lastWidth="853" MadCap:disableMasterStylesheet="true" MadCap:tocPath="" MadCap:InPreviewMode="false" MadCap:PreloadImages="false" MadCap:RuntimeFileType="Topic" MadCap:TargetType="WebHelp" lang="en-us" xml:lang="en-us" MadCap:PathToHelpSystem="../../../" MadCap:HelpSystemFileName="Default.xml" MadCap:SearchType="Stem">
|
|
<head><title>SELECT...CASE</title>
|
|
<link href="../../SkinSupport/MadCap.css" rel="stylesheet" />
|
|
<link href="../../Resources/Stylesheets/BSE_Help.css" rel="stylesheet" />
|
|
<script src="../../SkinSupport/MadCapAll.js" type="text/javascript">
|
|
</script>
|
|
</head>
|
|
<body>
|
|
<h1 class="code">SELECT...CASE</h1>
|
|
<div class="ImagePlusCaption">
|
|
<div class="Col2">
|
|
<p class="PlainText">
|
|
<img src="../../graphics/pgm_icon2.gif" border="0" alt="BS2 icon" title="BS2 icon" />
|
|
<img src="../../graphics/pgm_icon2e.gif" border="0" alt="BS2e icon" title="BS2e icon" />
|
|
<img src="../../graphics/pgm_icon2sx.gif" border="0" alt="BS2sx icon" title="BS2sx icon" />
|
|
<img src="../../graphics/pgm_icon2p.gif" border="0" alt="BS2p icon" title="BS2p icon" />
|
|
<img src="../../graphics/pgm_icon2pe.gif" border="0" alt="BS2pe icon" title="BS2pe icon" />
|
|
<img src="../../graphics/pgm_icon2px.gif" border="0" alt="BS2px icon" title="BS2px icon" /><span class="code_in_text"> {PBASIC 2.5}</span>
|
|
</p>
|
|
</div>
|
|
<p style="text-align: right;"><a href="../ExampleTopics/SelectCaseEx.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">SELECT...CASE Example</a>
|
|
</p>
|
|
<p> </p>
|
|
</div>
|
|
<p class="clear"> </p>
|
|
<p> </p>
|
|
<p class="PlainText">Syntax: <br></br><br></br>   <span class="keyword_in_text">SELECT</span> <![CDATA[ ]]><i>Expression</i><br></br>     <span class="keyword_in_text">CASE</span> <![CDATA[ ]]><i>Condition(s)</i><br></br>       <i>Statement(s)</i><br></br>   { <span class="keyword_in_text">CASE</span> <![CDATA[ ]]><i>Condition(s)</i><br></br>       <i>Statement(s)</i><br></br>     <span class="keyword_in_text">CASE ELSE</span><br></br>       <i>Statement(s)</i> }<br></br>   <span class="keyword_in_text">ENDSELECT</span></p>
|
|
<h2>Function</h2>
|
|
<p class="PlainText">Evaluate <i>Expression</i> and then conditionally execute a block of code based
|
|
on comparison to <i>Condition(s)</i>. After executing a block of code the
|
|
program continues at the line that follows <span class="keyword_in_text">ENDSELECT</span>. If no conditions
|
|
are found True and a <span class="keyword_in_text">CASE ELSE</span> block is included, the <span class="keyword_in_text">CASE ELSE</span>
|
|
code statements will execute. </p>
|
|
<ul>
|
|
<li value="1"><b><i>Expression</i></b> is a variable, a constant or an expression.</li>
|
|
<li value="2"><b><i>Condition</i></b> is a statement, that can be evaluated as True or
|
|
False. The <i>Condition</i> can be a very simple or very complex
|
|
relationship, as described below. Multiple conditions within the same
|
|
<span class="keyword_in_text">CASE</span> can be separated by commas ( , ).</li>
|
|
<li value="3"><b><i>Statement(s)</i></b> is any valid PBASIC statement or statements.
|
|
Multiple statements may be placed on the same line (though not recommended)
|
|
by separating each statement with a colon ( : ).</li>
|
|
</ul>
|
|
<h2>Quick Facts</h2>
|
|
<table width="100%" cellpadding="4" cellspacing="0" border="1">
|
|
<tr>
|
|
<td width="20%" align="center" bgcolor="#CFCFCF"> </td>
|
|
<td width="80%" align="center" bgcolor="#CFCFCF">BS2 Family</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" bgcolor="#CFCFCF">Comparison operators</td>
|
|
<td align="center">= (assumed if no operator), <>, >, <, >=,
|
|
<=</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" bgcolor="#CFCFCF">Conditional Logic Operators</td>
|
|
<td align="center">NOT, AND, OR, XOR</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" bgcolor="#CFCFCF"><i>Condition</i> format</td>
|
|
<td align="center">condition_op <i>value</i>   or  
|
|
<i>value1</i> TO <i>value2</i></td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" bgcolor="#CFCFCF">Parentheses</td>
|
|
<td align="center">Allowed</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" bgcolor="#CFCFCF">Nesting</td>
|
|
<td align="center">Up to 16 levels</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center" bgcolor="#CFCFCF">Related Commands</td>
|
|
<td align="center" colspan="1">
|
|
<p colspan="1" align="center"><a href="IF_THEN_ELSE.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IF…THEN…ELSE</a>, <a href="ON_GOSUB.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">ON...GOSUB</a>, <a href="BRANCH.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">BRANCH</a></p>
|
|
</td>
|
|
</tr>
|
|
</table>
|
|
<h2>Explanation</h2>
|
|
<p class="PlainText"><span class="keyword_in_text">SELECT...CASE</span> is an advanced decision-making structure and is often used
|
|
to replace compound <span class="keyword_in_text">IF...THEN...ELSE</span> structures. The available comparison
|
|
operators are:</p>
|
|
<center>
|
|
<table cellpadding="4" cellspacing="0" border="1">
|
|
<tr>
|
|
<td width="130" align="center" bgcolor="#CFCFCF">Comparison Operator Symbol</td>
|
|
<td width="170" align="center" bgcolor="#CFCFCF">Definition</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center">=</td>
|
|
<td align="center">Equal (assumed)</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center"><></td>
|
|
<td align="center">Not Equal</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center">></td>
|
|
<td align="center">Greater Than</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center"><</td>
|
|
<td align="center">Less Than</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center">>=</td>
|
|
<td align="center">Greater Than or Equal To</td>
|
|
</tr>
|
|
<tr>
|
|
<td align="center"><=</td>
|
|
<td align="center">Less Than or Equal To</td>
|
|
</tr>
|
|
</table>
|
|
</center>
|
|
<p> </p>
|
|
<p class="PlainText">Example:</p><pre class="BScode" xml:space="preserve">
|
|
SELECT irCmd
|
|
CASE 0 TO 3
|
|
HIGH irCmd ' enable selected output
|
|
FREQOUT Spkr, 50, 880 ' beep
|
|
|
|
CASE AllOff, Mute
|
|
OutA = %0000 ' all outputs off
|
|
|
|
CASE ELSE ' invalid command
|
|
DEBUG "Bad Command", CR
|
|
ENDSELECT
|
|
</pre>
|
|
<p class="PlainText">Here, the BASIC Stamp will examine the value of variable irCmd. If irCmd is
|
|
between zero and three (inclusive), the associated output (P0 .. P3) will be
|
|
made high and and the speaker will beep. If irCmd is equal to either AllOff or
|
|
Mute (constants), then outputs P0 - P3 will be made low. On any other value of
|
|
irCmd, a message will be displayed that indicates an invalid command.</p>
|
|
<p class="PlainText">See <a href="IF_THEN.htm" target="" title="" alt="" class="MCXref_0" xrefformat="{paratext}">IF…THEN</a> for additional details on the use of
|
|
comparison and conditional operators.</p>
|
|
<div class="Col2">
|
|
<div class="MasterFoot">
|
|
<p MadCap:conditions="BSEconditions.BSEWebHelp (Primary)-INCLUDE"><a href="../../HomeTopics/HomePage.htm">Go to Welcome page</a>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<div class="Col2">
|
|
<div class="MasterFoot">
|
|
<p style="text-align: right;"><span class="ContactInfoProjectName">BASIC Stamp Help</span> <![CDATA[ ]]><span class="ContactInfoVersion#">Version 2.5.4</span> <![CDATA[ ]]></p>
|
|
<p style="text-align: right;">Copyright © <span class="ContactInfoCompanyName">Parallax Inc.</span></p>
|
|
<p style="text-align: right;"><span class="SystemShortDate">8/8/2012</span>
|
|
</p>
|
|
</div>
|
|
</div>
|
|
<script type="text/javascript">/* <![CDATA[ */
|
|
|
|
var _gaq = _gaq || [];
|
|
_gaq.push(['_setAccount', 'UA-285614-1']);
|
|
_gaq.push(['_trackPageview']);
|
|
|
|
(function() {
|
|
var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
|
|
ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
|
|
var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
|
|
})();
|
|
|
|
/* ]]> */</script>
|
|
<script type="text/javascript" src="../../SkinSupport/MadCapBodyEnd.js">
|
|
</script>
|
|
</body>
|
|
</html> |