📄 class_book_begin033.htm
字号:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<style>
.redLink{ color:red;}
.blueLink{color:blue;}
A{font-size:12pt;text-decoration:none;}
P{font:12pt;line-height:22px;}
h2{font-size:30px;text-align:center;color:rgb(0,144,144);letter-spacing:.5em;font-weight:bold}
.whiteB{color:black;background-color:white;}
.blueB{color:yellow;background-color:blue;}
.blackB{color:white;background-color:black;}
</style>
<title>第三章:VB语言</title>
</head>
<script langue="javascript">
<!--
var source;
var flagDU="Up";
var oldClass="";
function ChangeColor(){
source=window.event.srcElement;
if (source.className=="redLink"){
source.className="blueLink";
}
else{
source.className="redLink";
}
}
function moveChangeBack(){
source=window.event.srcElement;
if (source.className==oldClass){oldClass=source.className;
if (flagDU=="Up"){
if (source.className="whiteB"){
source.className="blueB";
}else{
source.className="whiteB";
}
}else{source.className="blackB";
}
}else{//oldClass=source.className;
if (source.className=="whiteB"){
source.className="blueB";
}else{
source.className="whiteB";
}
}
}
function clickChangeBack(){
index01.className="whiteB"
index02.className="whiteB"
source=window.event.srcElement;
source.className="blackB";
flagDU="Down";
oldClass=source.className;
}
function returnValue(){
index01.className="whiteB";
index02.className="whiteB";
flagDU="Up";
}
function getAppVersion()
{
appname= navigator.appName;
appversion = navigator.appVersion;
majorver = appversion.substring(0, 1);
if ( (appname == "Netscape") && ( majorver >= 3 ) ) return 1;
if ( (appname == "Microsoft Internet Explorer") && (majorver>= 4) ) return 1;
return 0;
}
function switchGraphic(num, imgname) {
if (getAppVersion()) {
document[imgname].src = img[num].src;
}
}//-->
</script>
<body>
<script language="javascript">
<!--
imgsrc = new Array();
imgsrc[0] = "images/dot_blank.gif";
imgsrc[1] = "images/dot_filled.gif";
if (getAppVersion())
{
img = new Array();
for (i = 0; i < imgsrc.length; i++)
{
img[i] = new Image();
img[i].src = imgsrc[i];
}
}
//-->
</script>
<div align="center"><center>
<table border="0" cellpadding="8" cellspacing="0" width="100%">
<tr>
<td width="24%" valign="top"><h2><img src="../images/class_img.gif" WIDTH="160" HEIGHT="51"></h2>
<hr size="4" color="#FF0000" width="75%">
<p align="center"><img src="../images/menu_bar_jc_d.gif" WIDTH="150" HEIGHT="35"><img src="../images/dot_blank.gif" name="b1" WIDTH="10" HEIGHT="35"><br>
<a href="../class_api.htm" onMouseOver="switchGraphic('1','b2')" onMouseOut="switchGraphic('0','b2')"><img src="../images/menu_bar_api.gif" border="0" WIDTH="150" HEIGHT="35"></a><img src="../images/dot_blank.gif" name="b2" WIDTH="10" HEIGHT="35"><br>
<span align="center"><a href="../class_wz.htm" onMouseOver="switchGraphic('1','b5')" onMouseOut="switchGraphic('0','b5')"><img src="../images/menu_bar_wz.gif" border="0" WIDTH="150" HEIGHT="35"></a><img src="../images/dot_blank.gif" name="b5" WIDTH="10" HEIGHT="35"></span><br>
<a href="../class_tip.htm" onMouseOver="switchGraphic('1','b3')" onMouseOut="switchGraphic('0','b3')"><img src="../images/menu_bar_tip.gif" border="0" WIDTH="150" HEIGHT="35"></a><img src="../images/dot_blank.gif" name="b3" WIDTH="10" HEIGHT="35"><br>
<a href="../class_fqa.htm" onMouseOver="switchGraphic('1','b4')" onMouseOut="switchGraphic('0','b4')"><img src="../images/menu_bar_end_fqa.gif" border="0" WIDTH="150" HEIGHT="35"></a><img src="../images/dot_blank.gif" name="b4" WIDTH="10" HEIGHT="35"></p>
<p align="center"><a href="../context.htm"><img src="../images/logo_return.jpg" border="0" WIDTH="70" HEIGHT="260"></a></td>
<td width="76%" valign="top" align="center"><div align="center"><center><table border="0" cellpadding="8" cellspacing="0" width="27%" style="background-color: rgb(0,128,128)">
<tr>
<td width="100%" valign="top" align="center"><a name="top"><font size="5" color="#C0C0C0"><strong>VB入门教程</strong></font></a></td>
</tr>
</table>
</center></div><p><a href="class_book_begin031.htm">第一页</a> <a href="class_book_begin032.htm">第二页</a> 第三页 <a href="class_book_begin034.htm">第四页</a>
<a href="../class_book.htm">返回</a></p>
<div align="center"><center><table border="0" cellpadding="8" cellspacing="0" width="100%">
<tr>
<td width="100%"><font size="3" color="#8000FF"><strong><em>第三章:VB语言(3)</em></strong></font></td>
</tr>
<tr>
<td width="100%" style="background-color: rgb(232,255,254)"><p ALIGN="JUSTIFY"><strong><span style="line-height: 25px">五、循环语句</span></strong></p>
<blockquote>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px">循环结构是计算机语言里一种重要的结构,它的应用广泛,最简单的例子是累加器的作用,还可以用于穷举法,更直观的例子是把某件事重复指定的次数,这样就不用把要重复的语句输入多次,而通过循环结构完成,非常方便。</span></strong></p>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px">C语言里有一个“for”循环语句,VB里也有“For”关键字,作用也差不多,只是VB的“For”语句更容易理解。它的格式是:</span></strong></p>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px"><font color="#004080">For <循环变量>=<初赋值>
To <终值> [Step <步长>]</font></span></strong></p>
<blockquote>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px"><font color="#004080">……<br>
……</font></span></strong></p>
</blockquote>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px"><font color="#004080">Next <循环变量></font></span></strong></p>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px">在默认情况下,Step被设为“1”,可以省略,Step也可以设为负值,例如:</span></strong></p>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px"><font color="#004080">Dim a=0</font></span></strong></p>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px"><font color="#004080">For I=1
To 10 </font></span></strong></p>
<blockquote>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px"><font color="#004080">a=a+I</font></span></strong></p>
</blockquote>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px"><font color="#004080">Next I</font></span></strong></p>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px">这是一个最简单的累加器的例子,把1到10累加在一起,然后赋值给“a”这样的效果和上面是一样的,只不过是倒着加罢了,请看:</span></strong></p>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px"><font color="#004080">Dim a=0</font></span></strong></p>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px"><font color="#004080">For I=10
To 1 Step –1</font></span></strong></p>
<blockquote>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px"><font color="#004080">a=a+I</font></span></strong></p>
</blockquote>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px"><font color="#004080">Next I</font></span></strong></p>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px">While语句也是一个很常用的循环语句,它的形式很多。</span></strong></p>
<table border="0" cellpadding="0" cellspacing="0" width="100%" msimagelist>
<tr msimagelist>
<td valign="top" width="42" msimagelist><img src="bullet4.gif" width="13" height="12" hspace="14"></td>
<td valign="top" width="100%"><strong><span style="line-height: 25px">Do While …… Loop语句</span></strong></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="bullet4.gif" width="13" height="12" hspace="14"></td>
<td valign="top" width="100%"><strong><span style="line-height: 25px">While …… Wend
语句</span></strong></td msimagelist>
</tr>
<tr msimagelist>
<td valign="baseline" width="42" msimagelist><img src="bullet4.gif" width="13" height="12" hspace="14"></td>
<td valign="top" width="100%"><strong><span style="line-height: 25px">Do …… Loop While
</span></strong></td msimagelist>
</tr>
</table msimagelist>
<blockquote>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px">While后面都跟逻辑条件判断,“Do
While …… Loop语句”和“While …… Wend 语句”作用相似,都是先判断While后面的条件是否为“真”,如果为“真”则执行里面的语句,如果为“假”,则退出循环,循环直至条件为“假”终止。“Do
…… Loop While
”与前两者的区别在于,它不管条件的真假,都会先执行“Do”后面的语句,也就是说,它至少执行语句一次。</span></strong></p>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px">与While用法相似的还有Until语句,它是直至条件为真则终止循环,句式把While上述三个语句的While换成Until即可,但是因为容易记混,所以我建议只用While即可。Until
<条件>可以相当于While Not <条件>。</span></strong></p>
<p ALIGN="JUSTIFY"><strong><span style="line-height: 25px">For循环和Whlie循环应当根据适当的环境使用,它们有时也可替换。</span></strong></p>
</blockquote>
</blockquote>
</td>
</tr>
</table>
</center></div><p align="right"><strong><a href="#top"><img src="top2.gif" border="0" WIDTH="27" HEIGHT="30"></a></strong></td>
</tr>
</table>
</center></div>
<p> </p>
</body>
</html>
<!--webbot bot="HTMLMarkup" TAG="XBOT" StartSpan --></SCRIPT><!--webbot BOT="HTMLMarkup" endspan -->
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -