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

📄 vbs579.htm

📁 VBScript 是一种脚本语言
💻 HTM
字号:
<!DOCTYPE HTML PUBLIC "-//IETF//DTD HTML//EN"><HTML>
<HEAD><TITLE>For...Next Statement</TITLE> 
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=iso8859-1">
<META NAME="MS.LOCALE" CONTENT="EN-US">
<META NAME="PRODUCT" CONTENT="Visual Basic Scripting Edition">
<META NAME="TECHNOLOGY" CONTENT="SCRIPTING">
<META NAME="CATEGORY" CONTENT="Language Reference">

<META NAME="Keywords" CONTENT="To,For statement,Next,Step,loops,counter,Exit For,program control,control structures,repeating instructions,instructions repeating,instructions"><META NAME="Description" CONTENT="For...Next Statement"></HEAD>
<BODY BGCOLOR=FFFFFF LINK=#0033CC>
<!--TOOLBAR_START-->
<!--TOOLBAR_EXEMPT-->
<!--TOOLBAR_END-->
<FONT FACE="Verdana, Arial, Helvetica" SIZE=2>
<TABLE BORDER=0 CELLPADDING=0 CELLSPACING=0 WIDTH=100%><TR VALIGN=TOP><TD WIDTH=360>
<FONT SIZE=1 COLOR=#660033>Microsoft&#174; Visual Basic&#174; Scripting Edition</FONT><BR>
<FONT SIZE=5 COLOR=#660033><B>For...Next Statement</B></FONT>

</TD>
<TD ALIGN=RIGHT>
<FONT SIZE=2>&nbsp;<A HREF="vbstoc.htm">Language&nbsp;Reference</A>&nbsp;<BR>
<A HREF="vbs16.htm">Version&nbsp;1</A>&nbsp;<P></FONT>
</TD></TR>
</TABLE> 

<FONT SIZE=2><p>
<A HREF="vbs580.htm">See Also</A></FONT>
<hr noshade size=1>

<H5>Description</H5>
<BLOCKQUOTE>Repeats a group of statements a specified number of times.</BLOCKQUOTE>

<H5>Syntax</H5>
<BLOCKQUOTE>
<b>For</b> <i>counter</i> <b>=</b> <i>start</i> <b>To</b> <i>end</i> [<b>Step</b> <i>step</i>]<BR>
&nbsp;&nbsp;&nbsp;&nbsp;[<i>statements</i>]<BR>
&nbsp;&nbsp;&nbsp;&nbsp;[<b>Exit For</b>]<BR>
&nbsp;&nbsp;&nbsp;&nbsp;[<i>statements</i>]<BR>
<b>Next</b><p>

The <b>For...Next</b> statement syntax has these parts:<P>

<TABLE WIDTH=87% BORDER=1 CELLPADDING=5 CELLSPACING=0>
<TR VALIGN=TOP BGCOLOR="#DDDDDD">
<TD><FONT SIZE=2><b>Part</b></FONT></TD>
<TD><FONT SIZE=2><b>Description</b></FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>counter</i></FONT></TD>
<TD><FONT SIZE=2>Numeric variable used as a loop counter. The variable can't be an <A HREF="vbs0.htm#defArray">array</A> element or an element of a user-defined type.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>start</i></FONT></TD>
<TD><FONT SIZE=2>Initial value of <i>counter</i>.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>end</i></FONT></TD>
<TD><FONT SIZE=2>Final value of <i>counter</i>.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>step</i></FONT></TD>
<TD><FONT SIZE=2>Amount <i>counter</i> is changed each time through the loop. If not specified, <i>step</i> defaults to one.</FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2><i>statements</i></FONT></TD>
<TD><FONT SIZE=2>One or more statements between <b>For</b> and <b>Next</b> that are executed the specified number of times.</FONT></TD></TR>
</TABLE>
</BLOCKQUOTE>

<H5>Remarks</H5>
<BLOCKQUOTE>The <i>step</i> argument can be either positive or negative. The value of the <i>step</i> argument determines loop processing as follows:<P>

<TABLE WIDTH=87% BORDER=1 CELLPADDING=5 CELLSPACING=0>
<TR VALIGN=TOP BGCOLOR="#DDDDDD">
<TD><FONT SIZE=2><b>Value</b></FONT></TD>
<TD><FONT SIZE=2><b>Loop executes if</b></FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2>Positive or 0</FONT></TD>
<TD><FONT SIZE=2><i>counter</i> &lt;= <i>end</i></FONT></TD></TR>
<TR VALIGN=TOP>
<TD><FONT SIZE=2>Negative</FONT></TD>
<TD><FONT SIZE=2><i>counter</i> &gt;= <i>end</i></FONT></TD></TR>
</TABLE>
<P>
Once the loop starts and all statements in the loop have executed, <i>step</i> is added to <i>counter</i>. At this point, either the statements in the loop execute again (based on the same test that caused the loop to execute initially), or the loop is exited and execution continues with the statement following the <b>Next</b> statement.
<TABLE CELLSPACING=0 CELLPADDING=0 BORDER=0 WIDTH=87%><TR><TD COLSPAN=2 VALIGN=BOTTOM><HR noshade size=1></TD></TR><TR>
<TD VALIGN=TOP><FONT SIZE=2><b>Tip</b>&nbsp;&nbsp;Changing the value of <i>counter</i> while inside a loop can make it more difficult to read and debug your code.</FONT></TD></TR>
<TR><TD COLSPAN=2 VALIGN=TOP><HR noshade size=1></TD></TR></TABLE>
<b>Exit For</b> can only be used within a <b>For Each...Next</b> or <b>For...Next</b> control structure to provide an alternate way to exit. Any number of <b>Exit For</b> statements may be placed anywhere in the loop. <b>Exit For </b>is often used with the evaluation of some condition (for example, <b>If...Then</b>), and transfers control to the statement immediately following <b>Next</b>.<P>
You can nest <b>For...Next</b> loops by placing one <b>For...Next</b> loop within another. Give each loop a unique variable name as its <i>counter</i>. The following construction is correct:

<BLOCKQUOTE><PRE><FONT FACE="Courier New" SIZE=3><FONT COLOR="#FF0000">For</FONT> I = 1 <FONT COLOR="#FF0000">To</FONT> 10
    <FONT COLOR="#FF0000">For</FONT> J = 1 <FONT COLOR="#FF0000">To</FONT> 10
        <FONT COLOR="#FF0000">For</FONT> K = 1 <FONT COLOR="#FF0000">To</FONT> 10
        <b>. . .</b>
        <FONT COLOR="#FF0000">Next</FONT>
    <FONT COLOR="#FF0000">Next</FONT>
<FONT COLOR="#FF0000">Next</FONT>
</FONT></PRE>
</BLOCKQUOTE>
</BLOCKQUOTE>

<hr noshade size=1>
<p align=center><em><a href="../../common/colegal.htm">&copy; 1997 by Microsoft Corporation. All rights reserved.</a></em></p> 
</FONT></BODY></HTML>

















































































⌨️ 快捷键说明

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