📄 ch4_8_2.htm
字号:
<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title>while 循环</title><meta name="GENERATOR" content="Microsoft FrontPage 3.0"></head><body background="../img3/bg0000.gif"><script language="JAVASCRIPT"><!--if (navigator.onLine){document.write("<!-- Spidersoft WebZIP Ad Banner Insert -->");document.write("<TABLE width=100% border=0 cellpadding=0 cellspacing=0>");document.write("<TR>");document.write("<TD>");document.write("<ILAYER id=ad1 visibility=hidden height=60></ILAYER>");document.write("<NOLAYER>");document.write("<IFRAME SRC='http://www.spidersoft.com/ads/bwz468_60.htm' width=100% height=60 marginwidth=0 marginheight=0 hspace=0 vspace=0 frameborder=0 scrolling=no></IFRAME>");document.write("</NOLAYER>");document.write("</TD>");document.write("</TR>");document.write("</TABLE>");document.write("<!-- End of Spidersoft WebZIP Ad Banner Insert-->");} //--></script><p><strong><big><big><big><font COLOR="#0000FF">4.8.2 While 循环</font></big></big></big></strong></p><p><big><font COLOR="#0000FF">While 语句用于满足一定条件的循环,语法结构如下:</font></big></p><hr><p><font COLOR="#FF0000">while</font></p><p><font COLOR="#FF0000">while expression</font> <br><br><font COLOR="#FF0000">command group A</font> <br><br><font COLOR="#FF0000">end</font> <br><br><br><font COLOR="#FF0000">sum = 0;</font> <br><br><font COLOR="#FF0000">k = 1;</font> <br><br><font COLOR="#FF0000">while x(k) >= 0 & k <= length(k)</font> <br><br><font COLOR="#FF0000">sum = sum + x(k);</font> <br><br><font COLOR="#FF0000">k = k+1;</font> <br><br><font COLOR="#FF0000">end</font> </p><p>此外可以利用<font color="#FF0000">break</font>命令跳出<font color="#FF0000">for</font>,<font color="#FF0000">while</font>循环,如下例,计算MATLAB可以计算的最小正值:</p><p><font COLOR="#FF0000">>> num=0; EPS=1; <br><br>>> for num=1:1000 <br><br>EPS=EPS/2; <br><br>if (1+EPS) <= 1 <br><br>break <br><br>end <br><br>end <br><br>>> EPS, num <br><br>>> EPS = <br><br>1.1102e-016 <br><br>>> num = <br><br>53 </font></p><font COLOR="#FF0000"><hr></font><p><font COLOR="#FF0000"><a HREF="ch4_8_1.htm" tppabs="http://webclass.ncu.edu.tw/~junwu/ch4_8_1.htm"><img SRC="../img3/lastpage.gif" tppabs="http://webclass.ncu.edu.tw/~junwu/lastpage.gif" BORDER="0" WIDTH="42" HEIGHT="42"></a></font> <a HREF="../chapter5/ch5.htm" tppabs="http://webclass.ncu.edu.tw/~junwu/ch5.htm"><img SRC="../img3/nextpage.gif" tppabs="http://webclass.ncu.edu.tw/~junwu/nextpage.gif" HSPACE="10" BORDER="0" WIDTH="42" HEIGHT="42"></a> <a HREF="../index.html" tppabs="http://webclass.ncu.edu.tw/~junwu/index.html"><img SRC="../img3/outline.gif" tppabs="http://webclass.ncu.edu.tw/~junwu/outline.gif" HSPACE="6" BORDER="0" WIDTH="42" HEIGHT="42"></a> </p><p><font color="#FF00FF">上一页 下一页 讲义大纲</font></p></body></html>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -