⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 050-054.html

📁 dshfghfhhgsfgfghfhfghgfhfghfgh fg hfg hh ghghf hgf hghg gh fg hg hfg hfh f hg hgfh gkjh kjkh g yj f
💻 HTML
字号:
<HTML>
<HEAD>
<META name=vsisbn content="1558515682"><META name=vstitle content="Java Digital Signal Processing"><META name=vsauthor content="Douglas A. Lyon"><META name=vsimprint content="M&T Books"><META name=vspublisher content="IDG Books Worldwide, Inc."><META name=vspubdate content="11/01/97"><META name=vscategory content="Web and Software Development: Programming, Scripting, and Markup Languages: Java"><TITLE>Java Digital Signal Processing:Java Programming: The Basics</TITLE>
<!-- HEADER --><STYLE type="text/css">  <!-- A:hover  { 	color : Red; } --></STYLE><META NAME="ROBOTS" CONTENT="NOINDEX, NOFOLLOW">
<!--ISBN=1558515682//-->
<!--TITLE=Java Digital Signal Processing//-->
<!--AUTHOR=Douglas A. Lyon//-->
<!--PUBLISHER=IDG Books Worldwide, Inc.//-->
<!--IMPRINT=M & T Books//-->
<!--CHAPTER=2//-->
<!--PAGES=050-054//-->
<!--UNASSIGNED1//-->
<!--UNASSIGNED2//-->

<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="047-050.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="054-057.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>
<P><BR></P>
<H4 ALIGN="LEFT"><A NAME="Heading7"></A><FONT COLOR="#000077">Flow of Control</FONT></H4>
<P>This section describes Java&#146;s features for altering the flow of control. Java is strongly typed, so <I>if</I>, <I>for</I>, and <I>while</I> statements require Boolean expressions as arguments. In fact, all flow of control statements require Boolean expressions, with the single exception of the <I>switch</I> statement, which permits an integer type expression.</P>
<P><FONT SIZE="+1"><B>Expressions</B></FONT></P>
<P>Central to the use of the flow of control is the notion of a Boolean type expression. Unlike C and C&#43;&#43;, Java will not accept an expression that is of integer type. The following MBNF defines the expression statement in Java along with the testing expression and the logical expression:
</P>
<!-- CODE //-->
<PRE>
expression  -&gt;
numericExpression
| testingExpression   | logicalExpression  |
stringExpression  | bitExpression   |
castingExpression   | creatingExpression   |
literalExpression   |  "null"   |
"super"   |  "this"   |
identifier   |  (  "(" expression  ")"  )   |
( expression   (  (  "("  [arglist]  ")"  )   |
(  "[" expression  "]"  )   |  (  "." expression  )   |
(  "," expression  )   |
(  "instanceof"  ( className | interfaceName )  )   )  )  .
numericExpression  -&gt;
(  (  "-"   |  "&#43;&#43;"   |  "--"  )  expression )   |
( expression   (  "&#43;&#43;"   |  "--"  )  )   |
( expression   (  "&#43;"   |  "&#43;="   |  "-"
|  "-="   |  "*"   |  "*="   |  "/"   |  "/="   |  "%"   |  "%="  )
expression  )  .
testingExpression  -&gt;
( expression
(  "&gt;"   |  "&lt;"   |  "&gt;="   |  "&lt;="   |  "=="   |  "!="  )
expression  )  .
logicalExpression  -&gt;
(  "!" expression )   |  ( expression
(  "&#38;"   |  "&#38;="   |  "|"   |  "|="   |  "^"   |  "^="   |
(  "&#38;&#38;"  )   |  "||="   |  "%"   |  "%="  )  expression  )   |
( expression  "?" expression  ":" expression )   |  "true"   |  "false"  .
</PRE>
<!-- END CODE //-->
<P>In the following sections we give examples of expressions that alter the flow of control.
</P>
<P><FONT SIZE="+1"><B>If</B></FONT></P>
<P>The <I>if</I> statement in Java requires a boolean type expression:</P>
<!-- CODE SNIP //-->
<PRE>
ifStatement -&gt;
            &#147;if&#148;  &#147;(&#147; expression
            &#147;)&#148; statement   [ &#147;else&#148;
            statement]  .
   if (type.compareTo(&#147;ConstantValue&#148;) == 0) &#123;
   if (i &gt;= out.length) &#123;
   if (e.target == saveSound_mi) &#123;
   if (e.target == graphSound_mi)  &#123;
</PRE>
<!-- END CODE SNIP //-->
<P>The <I>then</I> part of the <I>if</I> may take the shape of any valid statement. No &#123;&#125; characters are required:</P>
<!-- CODE SNIP //-->
<PRE>
     if (Math.abs(return_val) &lt; 0.99)
          return return_val;
     else return 0;
</PRE>
<!-- END CODE SNIP //-->
<P>An extended clause is often indented to indicate when the clause has ended. Sometimes it is good style to indicate the end of the clause with a comment. For example:
</P>
<!-- CODE SNIP //-->
<PRE>
     if (interfaces == null) dos.writeShort(0);
       else &#123;
          dos.writeShort(interfaces.length);
          for (int i = 0; i &lt; interfaces.length; i&#43;&#43;)
              dos.writeShort(
                   ConstantPoolInfo.indexOf(
                        interfaces[i], constantPool));
&#125; // end else
</PRE>
<!-- END CODE SNIP //-->
<P>This practice is particularly good when the beginning of a clause is off the screen. Poor use of indentation and comments can make code hard to read. Consider the following example:
</P>
<!-- CODE SNIP //-->
<PRE>
if(x1 &lt; datarect.x) x1 = datarect.x;
      else if(x1 &gt; datarect.x &#43; datarect.width )
          x1 = datarect.x &#43; datarect.width;

if(y1 &lt; datarect.y) y1 = datarect.y;
       else if(y1 &gt; datarect.y &#43; datarect.height )
          y1 = datarect.y &#43; datarect.height;
</PRE>
<!-- END CODE SNIP //-->
<P>Now compare the preceding code with the following code:
</P>
<!-- CODE SNIP //-->
<PRE>
  if (x1 &lt; datarect.x) x1 = datarect.x;
  else if (x1 &gt; datarect.x &#43; datarect.width )
            x1 = datarect.x &#43; datarect.width;

if (y1 &lt; datarect.y) y1 = datarect.y;
 else if (y1 &gt; datarect.y &#43; datarect.height )
            y1 = datarect.y &#43; datarect.height;
</PRE>
<!-- END CODE SNIP //-->
<BLOCKQUOTE>
<P><FONT SIZE="-1"><HR><B>NOTE:&nbsp;&nbsp;</B><I>Else if</I> is used as a word pair, significantly cleaning up and shortening the code.<HR></FONT>
</BLOCKQUOTE>
<P>This example, is a long <I>if else</I> chain:</P>
<!-- CODE //-->
<PRE>
if(xminText.equals(e.target)) &#123;
     xmaxText.requestFocus();
     return true;
   &#125; else
   if(xmaxText.equals(e.target)) &#123;
     yminText.requestFocus();
     return true;
   &#125; else
   if(yminText.equals(e.target)) &#123;
     ymaxText.requestFocus();
     return true;
   &#125; else
   if(ymaxText.equals(e.target)) &#123;
     xminText.requestFocus();
     return true;
  &#125;
</PRE>
<!-- END CODE //-->
<P>Now let&#146;s convert it into the <I>else if</I> style:</P>
<!-- CODE //-->
<PRE>
if(xminText.equals(e.target)) &#123;
     xmaxText.requestFocus();
     return true;
&#125; else if(xmaxText.equals(e.target)) &#123;
          yminText.requestFocus();
          return true;
&#125; else if(yminText.equals(e.target)) &#123;
          ymaxText.requestFocus();
          return true;
&#125; else if(ymaxText.equals(e.target)) &#123;
          xminText.requestFocus();
          return true;
&#125;
</PRE>
<!-- END CODE //-->
<P>Such long dispatches are common in Java.
</P><P><BR></P>
<CENTER>
<TABLE BORDER>
<TR>
<TD><A HREF="047-050.html">Previous</A></TD>
<TD><A HREF="../ewtoc.html">Table of Contents</A></TD>
<TD><A HREF="054-057.html">Next</A></TD>
</TR>
</TABLE>
</CENTER>

<hr width="90%" size="1" noshade><div align="center"><font face="Verdana,sans-serif" size="1">Copyright &copy; <a href="/reference/idgbooks00001.html">IDG Books Worldwide, Inc.</a></font></div>
<!-- all of the reference materials (books) have the footer and subfoot reveresed --><!-- reference_subfoot = footer --><!-- reference_footer = subfoot --></BODY></HTML><!-- END FOOTER -->

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -