亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频

? 歡迎來到蟲蟲下載站! | ?? 資源下載 ?? 資源專輯 ?? 關于我們
? 蟲蟲下載站

?? ch07.htm

?? good book for learning c++ standard language
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
5:
6:      int main()
7:      {
8:         int counter;
9:         cout << "How many hellos? ";
10:        cin >> counter;
11:        do
12:        {
13:           cout << "Hello\n";
14:           counter--;
15:        }  while (counter >0 );
16:        cout << "Counter is: " << counter << endl;
17:         return 0;
<TT>18: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: How many hellos? 2
Hello
Hello
Counter is: 0
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>The user is prompted for
a starting value on line 9, which is stored in the integer variable <TT>counter</TT>.
In the <TT>do...while</TT> loop, the body of the loop is entered before the condition
is tested, and therefore the body of the loop is guaranteed to run at least once.
On line 13 the message is printed, on line 14 the counter is decremented, and on
line 15 the condition is tested. If the condition evaluates <TT>TRUE</TT>, execution
jumps to the top of the loop on line 13; otherwise, it falls through to line 16.<BR>
The <TT>continue</TT> and <TT>break</TT> statements work in the <TT>do...while</TT>
loop exactly as they do in the <TT>while</TT> loop. The only difference between a
<TT>while</TT> loop and a <TT>do...while</TT> loop is when the <TT>condition</TT>
is tested.
<H3 ALIGN="CENTER"><A NAME="Heading30"></A><FONT COLOR="#000077">The do...while Statement</FONT></H3>
<P>The syntax for the <TT>do...while</TT> statement is as follows:</P>
<PRE><FONT COLOR="#0066FF">do
statement
while (condition);
</FONT></PRE>
<P>statement is executed, and then condition is evaluated. If condition is <TT>TRUE</TT>,
the loop is repeated; otherwise, the loop ends. The statements and conditions are
otherwise identical to the <TT>while</TT> loop. Example 1</P>
<PRE><FONT COLOR="#0066FF">// count to 10
int x = 0;
do
cout &lt;&lt; &quot;X: &quot; &lt;&lt; x++;
while (x &lt; 10)
</FONT></PRE>
<P>Example 2</P>
<PRE><FONT COLOR="#0066FF">// print lowercase alphabet.
char ch = `a';
do
{
cout &lt;&lt; ch &lt;&lt; ` `;
ch++;
} while ( ch &lt;= `z' );
</FONT></PRE>


<BLOCKQUOTE>
	<P>
<HR>
<B>DO</B> use <TT>do...while</TT> when you want to ensure the loop is executed at
	least once. <B>DO </B>use <TT>while</TT> loops when you want to skip the loop if
	the condition is false. <B>DO</B> test all loops to make sure they do what you expect.
	
<HR>


</BLOCKQUOTE>

<H3 ALIGN="CENTER"><A NAME="Heading31"></A><FONT COLOR="#000077">for Loops</FONT></H3>
<P>When programming <TT>while</TT> loops, you'll often find yourself setting up a
starting condition, testing to see if the condition is true, and incrementing or
otherwise changing a variable each time through the loop. Listing 7.8 demonstrates
this.</P>
<P><A NAME="Heading32"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 7.8. While reexamined</B></FONT><FONT
SIZE="2" COLOR="#000077"><B>.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:    // Listing 7.8
2:    // Looping with while
3:
4:    #include &lt;iostream.h&gt;
5:
6:    int main()
7:    {
8:      int counter = 0;
9:
10:      while(counter &lt; 5)
11:      {
12:           counter++;
13:           cout &lt;&lt; &quot;Looping!  &quot;;
14:      }
15:
16:      cout &lt;&lt; &quot;\nCounter: &quot; &lt;&lt; counter &lt;&lt; &quot;.\n&quot;;
17:       return 0;
<TT>18: }</TT>
Output: Looping!  Looping!  Looping!  Looping!  Looping!
Counter: 5.
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>The condition is set on line
8: <TT>counter</TT> is initialized to <TT>0</TT>. On line 10, <TT>counter</TT> is
tested to see whether it is less than 5. <TT>counter</TT> is incremented on line
12. On line 16, a simple message is printed, but you can imagine that more important
work could be done for each increment of the <TT>counter</TT>.<BR>
A <TT>for</TT> loop combines three steps into one statement. The three steps are
initialization, test, and increment. A <TT>for</TT> statement consists of the keyword
<TT>for</TT> followed by a pair of parentheses. Within the parentheses are three
statements separated by semicolons.</P>
<P>The first statement is the initialization. Any legal C++ statement can be put
here, but typically this is used to create and initialize a counting variable. Statement
2 is the test, and any legal C++ expression can be used here. This serves the same
role as the condition in the <TT>while</TT> loop. Statement 3 is the action. Typically
a value is incremented or decremented, though any legal C++ statement can be put
here. Note that statements 1 and 3 can be any legal C++ statement, but statement
2 must be an expression--a C++ statement that returns a value. Listing 7.9 demonstrates
a <TT>for</TT> loop.</P>
<P><A NAME="Heading34"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 7.9. Demonstrating
the for loop.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:      // Listing 7.9
2:      // Looping with for
3:
4:      #include &lt;iostream.h&gt;
5:
6:      int main()
7:      {
8:        int counter;
9:        for (counter = 0; counter &lt; 5; counter++)
10:          cout &lt;&lt; &quot;Looping! &quot;;
11:
12:        cout &lt;&lt; &quot;\nCounter: &quot; &lt;&lt; counter &lt;&lt; &quot;.\n&quot;;
13:         return 0;
<TT>14: }</TT></FONT>
<FONT COLOR="#0066FF">Output: Looping!  Looping!  Looping!  Looping!  Looping!
Counter: 5.
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>The <TT>for</TT> statement
on line 8 combines the initialization of <TT>counter</TT>, the test that <TT>counter</TT>
is less than 5, and the increment of <TT>counter</TT> all into one line. The body
of the <TT>for</TT> statement is on line 9. Of course, a block could be used here
as well.
<H3 ALIGN="CENTER"><A NAME="Heading36"></A><FONT COLOR="#000077">The for Statement</FONT></H3>
<P>The syntax for the <TT>for</TT> statement is as follows:</P>
<PRE><FONT COLOR="#0066FF">for (initialization; test; action )
statement;
</FONT></PRE>
<P>The initialization statement is used to initialize the state of a <TT>counter</TT>,
or to otherwise prepare for the loop. test is any C++ expression and is evaluated
each time through the loop. If test is <TT>TRUE</TT>, the action in the header is
executed (typically the counter is incremented) and then the body of the <TT>for</TT>
loop is executed. Example 1</P>
<PRE><FONT COLOR="#0066FF">// print Hello ten times
for (int i = 0; i&lt;10; i++)
cout &lt;&lt; &quot;Hello! &quot;;
</FONT></PRE>
<P>Example 2</P>
<PRE><FONT COLOR="#0066FF">for (int i = 0; i &lt; 10; i++)
{
    cout &lt;&lt; &quot;Hello!&quot; &lt;&lt; endl;
    cout &lt;&lt; &quot;the value of i is: &quot; &lt;&lt; i &lt;&lt; endl;
}
</FONT></PRE>
<H4 ALIGN="CENTER"><A NAME="Heading37"></A><FONT COLOR="#000077">Advanced for Loops</FONT></H4>
<P><TT>for</TT> statements are powerful and flexible. The three independent statements
(initialization, test, and action) lend themselves to a number of variations.</P>
<P>A <TT>for</TT> loop works in the following sequence:

<DL>
	<DD><B>1.</B> Performs the operations in the initialization.<BR>
	<BR>
	<B>2.</B> Evaluates the condition.<BR>
	<BR>
	<B>3.</B> If the condition is <TT>TRUE</TT>, executes the action statement and the
	loop.
</DL>

<P>After each time through, the loop repeats steps 2 and 3. Multiple Initialization
and Increments It is not uncommon to initialize more than one variable, to test a
compound logical expression, and to execute more than one statement. The initialization
and the action may be replaced by multiple C++ statements, each separated by a comma.
Listing 7.10 demonstrates the initialization and increment of two variables.</P>
<P><A NAME="Heading38"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 7.10. Demonstrating
multiple statements in for loops.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:  //listing 7.10
2:  // demonstrates multiple statements in
3:  // for loops
4:
5: #include &lt;iostream.h&gt;
6:
7:  int main()
8:  {
9:      for (int i=0, j=0; i&lt;3; i++, j++)
10:          cout &lt;&lt; &quot;i: &quot; &lt;&lt; i &lt;&lt; &quot; j: &quot; &lt;&lt; j &lt;&lt; endl;
11:     return 0;
<TT>12: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: i: 0  j: 0
i: 1  j: 1
i: 2  j: 2
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis: </B></FONT>On line 9, two variables, <TT>i</TT>
and <TT>j</TT>, are each initialized with the value <TT>0</TT>. The test (<TT>i&lt;3</TT>)
is evaluated, and because it is true, the body of the <TT>for</TT> statement is executed,
and the values are printed. Finally, the third clause in the <TT>for</TT> statement
is executed, and <TT>i</TT> and <TT>j</TT> are incremented.<BR>
Once line 10 completes, the condition is evaluated again, and if it remains true
the actions are repeated (<TT>i</TT> and <TT>j</TT> are again incremented), and the
body of loop is executed again. This continues until the test fails, in which case
the action statement is not executed, and control falls out of the loop. Null Statements
in for Loops Any or all of the statements in a <TT>for</TT> loop can be null. To
accomplish this, use the semicolon to mark where the statement would have been. To
create a <TT>for</TT> loop that acts exactly like a <TT>while</TT> loop, leave out
the first and third statements. Listing 7.11 illustrates this idea.</P>
<P><A NAME="Heading40"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 7.11. Null statements
in for loops</B></FONT><FONT SIZE="2" COLOR="#000077"><B>.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:    // Listing 7.11
2:    // For loops with null statements
3:
4:    #include &lt;iostream.h&gt;
5:
6:    int main()
7:    {
8:        int counter = 0;
9:
10:        for( ; counter &lt; 5; )
11:        {
12:           counter++;
13:           cout &lt;&lt; &quot;Looping!  &quot;;
14:        }
15:
16:        cout &lt;&lt; &quot;\nCounter: &quot; &lt;&lt; counter &lt;&lt; &quot;.\n&quot;;
17:       return 0;
<TT>18: }</TT></FONT>
<FONT COLOR="#0066FF">
output: Looping!  Looping!  Looping!  Looping!  Looping!
Counter: 5.
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>You may recognize this as
exactly like the <TT>while</TT> loop illustrated in Listing 7.8! On line 8, the counter
variable is initialized. The <TT>for</TT> statement on line 10 does not initialize
any values, but it does include a test for <TT>counter &lt; 5</TT>. There is no increment
statement, so this loop behaves exactly as if it had been written:</P>
<PRE><FONT COLOR="#0066FF">while (counter &lt; 5)</FONT></PRE>
<P>Once again, C++ gives you a number of ways to accomplish the same thing. No experienced
C++ programmer would use a <TT>for</TT> loop in this way, but it does illustrate
the flexibility of the <TT>for</TT> statement. In fact, it is possible, using <TT>break</TT>
and <TT>continue</TT>, to create a <TT>for</TT> loop with none of the three statements.
Listing 7.12 illustrates how.</P>
<P><A NAME="Heading42"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 7.12. Illustrating
empty for loop statement.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:     //Listing 7.12 illustrating
2:     //empty for loop statement
3:
4:     #include &lt;iostream.h&gt;
5:
6:     int main()
7:     {
8:         int counter=0;       // initialization
9:         int max;
10:         cout &lt;&lt; &quot;How many hellos?&quot;;
11:         cin &gt;&gt; max;
12:         for (;;)          // a for loop that doesn't end
13:         {
14:            if (counter &lt; max)       // test
15:            {
16:              cout &lt;&lt; &quot;Hello!\n&quot;;
17:              counter++;          // increment
18:            }
19:            else
20:                break;
21:         }
22:        return 0;
<TT>23: }</TT></FONT>
<FONT COLOR="#0066FF">
Output: How many hellos?3
Hello!
Hello!
Hello!
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>The <TT>for</TT> loop has
now been pushed to its absolute limit. Initialization, test, and action have all
been taken out of the <TT>for</TT> statement. The initialization is done on line
8, before the <TT>for</TT> loop begins. The test is done in a separate <TT>if</TT>
statement on line 14, and if the test succeeds, the action, an increment to <TT>counter</TT>,
is performed on line 17. If the test fails, breaking out of the loop occurs on line
20.<BR>
While this particular program is somewhat absurd, there are times when a <TT>for(;;)</TT>
loop or a <TT>while (1)</TT> loop is just what you'll want. You'll see an example
of a more reasonable use of such loops when <TT>switch</TT> statements are discussed
later today.
<H4 ALIGN="CENTER"><A NAME="Heading44"></A><FONT COLOR="#000077">Empty for Loops</FONT></H4>
<P>So much can be done in the header of a <TT>for</TT> statement, there are times
you won't need the body to do anything at all. In that case, be sure to put a null
statement (<TT>;</TT>) as the body of the loop. The semicolon can be on the same
line as the header, but this is easy to overlook. Listing 7.13 illustrates how to
use a null body in a <TT>for</TT> loop.</P>
<P><A NAME="Heading45"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 7.13. Illustrates
the null statement in a for loop.</B></FONT></P>

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
一区二区三区资源| 久久久久亚洲蜜桃| 不卡影院免费观看| 精品亚洲porn| 久久精品国产精品亚洲红杏| 精品国产一区二区亚洲人成毛片| 精品国产凹凸成av人导航| 亚洲综合成人网| 国产成人精品免费视频网站| 91精品国产一区二区三区| 中文字幕视频一区| 国产在线视频一区二区三区| 欧美二区乱c少妇| 亚洲三级在线免费| 国产v综合v亚洲欧| 欧美成人一区二区| 日本在线不卡视频| 欧美吻胸吃奶大尺度电影 | 国产午夜精品一区二区| 亚洲成a人片在线观看中文| 欧美视频在线一区二区三区| 久久精品一区蜜桃臀影院| 麻豆久久久久久久| 欧美高清精品3d| 亚洲狠狠爱一区二区三区| 成人ar影院免费观看视频| 久久久亚洲高清| 国产综合久久久久影院| 日韩欧美在线1卡| 欧美aa在线视频| 欧美一区二区三区喷汁尤物| 午夜影视日本亚洲欧洲精品| 欧美日免费三级在线| 一区二区三区精品在线观看| 日本高清成人免费播放| 亚洲激情六月丁香| 色88888久久久久久影院野外| 亚洲同性gay激情无套| 成人福利视频在线| 一本色道综合亚洲| 91麻豆国产自产在线观看| 91精品国产综合久久福利| 中文字幕一区二区日韩精品绯色| 石原莉奈在线亚洲三区| 99久久免费视频.com| 91精品国产91综合久久蜜臀| 中文字幕在线观看不卡视频| 看电视剧不卡顿的网站| 91视频免费观看| 久久色视频免费观看| 亚洲一区二区在线播放相泽 | 亚洲国产精品传媒在线观看| 亚洲国产精品一区二区久久恐怖片 | xnxx国产精品| 偷拍亚洲欧洲综合| 97精品久久久午夜一区二区三区| 日韩午夜激情电影| 亚洲成人av中文| av成人动漫在线观看| 精品免费国产一区二区三区四区| 一区二区三区高清不卡| 成人理论电影网| 久久久av毛片精品| 日韩国产一区二| 欧美日韩精品二区第二页| 亚洲摸摸操操av| 成人h动漫精品一区二区| 久久久国际精品| 国产自产高清不卡| 日韩久久精品一区| 日本伊人午夜精品| 欧美一区二区三区四区久久| 亚洲va在线va天堂| 欧美最新大片在线看| 亚洲黄色免费电影| 91精品福利视频| 一区二区高清免费观看影视大全| a级精品国产片在线观看| 国产精品国产三级国产普通话三级| 国产精品一区二区三区99| 久久欧美一区二区| 国产成人自拍网| 国产精品女同一区二区三区| av在线免费不卡| 亚洲欧洲中文日韩久久av乱码| 91免费观看在线| 亚洲精品国产成人久久av盗摄| 日本精品视频一区二区| 亚洲综合一二区| 在线不卡中文字幕| 久久国产麻豆精品| 久久久国产精品不卡| 不卡电影免费在线播放一区| 国产精品成人免费| 欧美主播一区二区三区美女| 青草国产精品久久久久久| 欧美一级理论片| 国产成+人+日韩+欧美+亚洲| 中文字幕一区二区三区不卡 | 久久久久久久久久久电影| 成人性生交大片免费看在线播放| 国产精品青草久久| 欧美在线一二三四区| 亚洲va国产天堂va久久en| 日韩一区二区麻豆国产| 国产精品主播直播| 亚洲免费观看视频| 欧美成人精品二区三区99精品| 国产ts人妖一区二区| 亚洲一区二区视频| 久久久久国产精品麻豆ai换脸| gogo大胆日本视频一区| 日本午夜一本久久久综合| 国产视频一区二区三区在线观看 | 欧美一区二区在线观看| 国产在线精品免费av| 亚洲欧美国产高清| 亚洲精品一区二区三区蜜桃下载| 99在线精品观看| 久久av资源站| 亚洲成人7777| 国产精品久久久久久久久久免费看| 欧美精品日日鲁夜夜添| 成人午夜激情片| 激情欧美一区二区| 亚洲主播在线播放| 国产精品美女久久久久久久久| 欧美日韩国产片| 97精品国产露脸对白| 国产精品亚洲а∨天堂免在线| 亚洲成av人片在线| 亚洲天堂2016| 国产精品色在线观看| 欧美变态tickle挠乳网站| 欧美日韩一区国产| 色综合久久久网| 国产高清无密码一区二区三区| 日韩精品亚洲专区| 亚洲一二三级电影| 国产精品久久久久一区| 久久久久88色偷偷免费| 欧美不卡一二三| 在线91免费看| 欧美日韩国产美| 欧美在线观看你懂的| 色综合色综合色综合色综合色综合 | 国产精品一区二区三区99| 青青草原综合久久大伊人精品| 亚洲精品成人a在线观看| 中文字幕国产一区二区| 国产亚洲人成网站| 欧美中文字幕一区| 一本大道av一区二区在线播放| 欧美一区欧美二区| 中文字幕av一区二区三区| 亚洲第一综合色| 国产成人精品免费在线| 欧美亚洲国产怡红院影院| 久久奇米777| 亚洲第一福利一区| 成人精品免费看| 欧美日韩国产在线观看| 国产精品国模大尺度视频| 日韩国产欧美在线观看| 99国产精品国产精品久久| 欧美一区二区日韩| 亚洲激情五月婷婷| 国产精品亚洲第一| 91精品国产综合久久久久| 国产精品久久久久久久久免费樱桃| 日本在线不卡视频| 在线视频亚洲一区| 欧美经典一区二区三区| av不卡一区二区三区| 欧美一区二区三区四区五区| 亚洲综合网站在线观看| 成a人片亚洲日本久久| 欧美精品一区二区三区在线 | 蜜臀av国产精品久久久久| 91免费版在线| 日本一区二区三区久久久久久久久不| 日本欧洲一区二区| 欧美视频在线一区二区三区| 国产精品日韩精品欧美在线| 久久99精品久久久久久国产越南| 在线欧美一区二区| 亚洲人成在线观看一区二区| 国产成人在线影院| 久久日一线二线三线suv| 蜜臀av一区二区三区| 在线不卡的av| 午夜欧美大尺度福利影院在线看| 91在线国内视频| 中文字幕一区二区三区精华液| 成人亚洲一区二区一| 亚洲黄色片在线观看| 九九**精品视频免费播放| 色综合天天性综合| 日韩欧美国产精品| 亚洲一区二区三区四区在线免费观看 |