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

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

?? ch07.htm

?? good book for learning c++ standard language
?? HTM
?? 第 1 頁 / 共 5 頁
字號:
Enter a large number: 100000
small: 2.........
Small: 33335 Large: 33334
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>This program is a game. Enter
two numbers, one small and one large. The smaller number will count up by ones, and
the larger number will count down by twos. The goal of the game is to guess when
they'll meet.<BR>
On lines 12-15, the numbers are entered. Line 20 sets up a <TT>while</TT> loop, which
will continue only as long as three conditions are met:<BR>
<BR>
<TT>small</TT> is not bigger than <TT>large</TT>.<BR>
<BR>
<TT>large</TT> isn't negative.<BR>
<BR>
<TT>small</TT> doesn't overrun the size of a small integer (<TT>MAXSMALL</TT>).<BR>
<BR>
On line 23, the value in <TT>small</TT> is calculated modulo 5,000. This does not
change the value in <TT>small</TT>; however, it only returns the value <TT>0</TT>
when <TT>small</TT> is an exact multiple of 5,000. Each time it is, a dot (<TT>.</TT>)
is printed to the screen to show progress. On line 26, <TT>small</TT> is incremented,
and on line 28, <TT>large</TT> is decremented by 2.<BR>
When any of the three conditions in the <TT>while</TT> loop fails, the loop ends
and execution of the program continues after the <TT>while</TT> loop's closing brace
on line 29.


<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>The modulus operator (%) and compound
	conditions are covered on Day 3, &quot;Variables and Constants.&quot; 
<HR>


</BLOCKQUOTE>

<H4 ALIGN="CENTER"><A NAME="Heading16"></A><FONT COLOR="#000077">continue and break</FONT></H4>
<P>At times you'll want to return to the top of a <TT>while</TT> loop before the
entire set of statements in the <TT>while</TT> loop is executed. The <TT>continue</TT>
statement jumps back to the top of the loop.</P>
<P>At other times, you may want to exit the loop before the exit conditions are met.
The <TT>break</TT> statement immediately exits the <TT>while</TT> loop, and program
execution resumes after the closing brace.</P>
<P>Listing 7.4 demonstrates the use of these statements. This time the game has become
more complicated. The user is invited to enter a <TT>small</TT> number and a <TT>large</TT>
number, a <TT>skip</TT> number, and a <TT>target</TT> number. The <TT>small</TT>
number will be incremented by one, and the <TT>large</TT> number will be decremented
by 2. The decrement will be skipped each time the <TT>small</TT> number is a multiple
of the <TT>skip</TT>. The game ends if <TT>small</TT> becomes larger than <TT>large</TT>.
If the <TT>large</TT> number reaches the <TT>target</TT> exactly, a statement is
printed and the game stops.</P>
<P>The user's goal is to put in a target number for the <TT>large</TT> number that
will stop the game.</P>
<P><A NAME="Heading17"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 7.4. break and
continue.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:    // Listing 7.4
2:    // Demonstrates break and continue
3:
4:    #include &lt;iostream.h&gt;
5:
6:    int main()
7:    {
8:      unsigned short small;
9:      unsigned long  large;
10:      unsigned long  skip;
11:      unsigned long target;
12:      const unsigned short MAXSMALL=65535;
13:
14:      cout &lt;&lt; &quot;Enter a small number: &quot;;
15:      cin &gt;&gt; small;
16:      cout &lt;&lt; &quot;Enter a large number: &quot;;
17:      cin &gt;&gt; large;
18:      cout &lt;&lt; &quot;Enter a skip number: &quot;;
19:      cin &gt;&gt; skip;
20:      cout &lt;&lt; &quot;Enter a target number: &quot;;
21:      cin &gt;&gt; target;
22:
23:    cout &lt;&lt; &quot;\n&quot;;
24:
25:     // set up 3 stop conditions for the loop
26:      while (small &lt; large &amp;&amp; large &gt; 0 &amp;&amp; small &lt; 65535)
27:
28:      {
29:
30:        small++;
31:
32:         if (small % skip == 0)  // skip the decrement?
33:         {
34:           cout &lt;&lt; &quot;skipping on &quot; &lt;&lt; small &lt;&lt; endl;
35:           continue;
36:         }
37:
38:         if (large == target)    // exact match for the target?
39:         {
40:           cout &lt;&lt; &quot;Target reached!&quot;;
41:           break;
42:         }
43:
44:         large-=2;
45:      }                   // end of while loop
46:
47:      cout &lt;&lt; &quot;\nSmall: &quot; &lt;&lt; small &lt;&lt; &quot; Large: &quot; &lt;&lt; large &lt;&lt; endl;
48:    return 0;
<TT>49: }</TT>
Output: Enter a small number: 2
Enter a large number: 20
Enter a skip number: 4
Enter a target number: 6
skipping on 4
skipping on 8

Small: 10 Large: 8
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis: </B></FONT>In this play, the user lost; <TT>small</TT>
became larger than <TT>large</TT> before the <TT>target</TT> number of 6 was reached.<BR>
On line 26, the <TT>while</TT> conditions are tested. If <TT>small</TT> continues
to be smaller than <TT>large</TT>, <TT>large</TT> is larger than 0, and <TT>small</TT>
hasn't overrun the maximum value for a small <TT>int</TT>, the body of the <TT>while</TT>
loop is entered.</P>
<P>On line 32, the <TT>small</TT> value is taken modulo the <TT>skip</TT> value.
If <TT>small</TT> is a multiple of <TT>skip</TT>, the <TT>continue</TT> statement
is reached and program execution jumps to the top of the loop at line 26. This effectively
skips over the test for the <TT>target</TT> and the decrement of <TT>large</TT>.</P>
<P>On line 38, <TT>target</TT> is tested against the value for <TT>large</TT>. If
they are the same, the user has won. A message is printed and the <TT>break</TT>
statement is reached. This causes an immediate break out of the <TT>while</TT> loop,
and program execution resumes on line 46.


<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>NOTE:</B></FONT><B> </B>Both <TT>continue</TT> and <TT>break</TT>
	should be used with caution. They are the next most dangerous commands after <TT>goto</TT>,
	for much the same reason. Programs that suddenly change direction are harder to understand,
	and liberal use of <TT>continue</TT> and <TT>break</TT> can render even a small <TT>while</TT>
	loop unreadable. 
<HR>


</BLOCKQUOTE>

<H3 ALIGN="CENTER"><A NAME="Heading19"></A><FONT COLOR="#000077">The continue Statement</FONT></H3>
<P><TT>continue;</TT> causes a <TT>while</TT> or <TT>for</TT> loop to begin again
at the top of the loop. Example</P>
<PRE><FONT COLOR="#0066FF">if (value &gt; 10)
     goto end;

if (value &lt; 10)
     goto end;

cout &lt;&lt; &quot;value is 10!&quot;;

end:

cout &lt;&lt; &quot;done&quot;;
</FONT></PRE>
<H3 ALIGN="CENTER"><A NAME="Heading20"></A><FONT COLOR="#000077">The break Statement</FONT></H3>
<P><TT>break;</TT> causes the immediate end of a <TT>while</TT> or <TT>for</TT> loop.
Execution jumps to the closing brace. Example</P>
<PRE><FONT COLOR="#0066FF">while (condition)
{
    if (condition2)
        break;
    // statements;
}
</FONT></PRE>
<H4 ALIGN="CENTER"><A NAME="Heading21"></A><FONT COLOR="#000077">while (1) Loops</FONT></H4>
<P>The condition tested in a <TT>while</TT> loop can be any valid C++ expression.
As long as that condition remains true, the <TT>while</TT> loop will continue. You
can create a loop that will never end by using the number 1 for the condition to
be tested. Since 1 is always true, the loop will never end, unless a <TT>break</TT>
statement is reached. Listing 7.5 demonstrates counting to 10 using this construct.</P>
<P><A NAME="Heading22"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 7.5. while (1)
loops.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:    // Listing 7.5
2:    // Demonstrates a while true loop
3:
4:    #include &lt;iostream.h&gt;
5:
6:    int main()
7:    {
8:      int counter = 0;
9:
10:      while (1)
11:      {
12:         counter ++;
13:         if (counter &gt; 10)
14:             break;
15:      }
16:      cout &lt;&lt; &quot;Counter: &quot; &lt;&lt; counter &lt;&lt; &quot;\n&quot;;
17:       return 0;
<TT>18: </TT>
Output: Counter: 11
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>On line 10, a <TT>while</TT>
loop is set up with a condition that can never be false. The loop increments the
<TT>counter</TT> variable on line 12 and then on line 13 tests to see whether <TT>counter</TT>
has gone past 10. If it hasn't, the <TT>while</TT> loop iterates. If <TT>counter</TT>
is greater than 10, the <TT>break</TT> on line 14 ends the <TT>while</TT> loop, and
program execution falls through to line 16, where the results are printed.<BR>
This program works, but it isn't pretty. This is a good example of using the wrong
tool for the job. The same thing can be accomplished by putting the test of <TT>counter</TT>'s
value where it belongs--in the <TT>while</TT> condition.


<BLOCKQUOTE>
	<P>
<HR>
<FONT COLOR="#000077"><B>WARNING:</B></FONT><B> </B>Eternal loops such as <TT>while
	(1)</TT> can cause your computer to hang if the exit condition is never reached.
	Use these with caution and test them thoroughly. 
<HR>


</BLOCKQUOTE>

<P>C++ gives you many different ways to accomplish the same task. The real trick
is picking the right tool for the particular job.


<BLOCKQUOTE>
	<P>
<HR>
<B>DON'T</B> use the <TT>goto</TT> statement. <B>DO</B> use <TT>while</TT> loops
	to iterate while a condition is true. <B>DO</B> exercise caution when using <TT>continue</TT>
	and <TT>break </TT>statements. <B>DO</B> make sure your loop will eventually end.
	
<HR>


</BLOCKQUOTE>

<H3 ALIGN="CENTER"><A NAME="Heading24"></A><FONT COLOR="#000077">do...while Loops</FONT></H3>
<P>It is possible that the body of a <TT>while</TT> loop will never execute. The
<TT>while</TT> statement checks its condition before executing any of its statements,
and if the condition evaluates <TT>false</TT>, the entire body of the <TT>while</TT>
loop is skipped. Listing 7.6 illustrates this.</P>
<P><A NAME="Heading25"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 7.6. Skipping
the body of the while Loop</B></FONT><FONT SIZE="2" COLOR="#000077"><B>.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:     // Listing 7.6
2:      // Demonstrates skipping the body of
3:      // the while loop when the condition is false.
4:
5:      #include &lt;iostream.h&gt;
6:
7:      int main()
8:      {
9:         int counter;
10:        cout &lt;&lt; &quot;How many hellos?: &quot;;
11:        cin &gt;&gt; counter;
12:        while (counter &gt; 0)
13:        {
14:           cout &lt;&lt; &quot;Hello!\n&quot;;
15:           counter--;
16:        }
17:        cout &lt;&lt; &quot;Counter is OutPut: &quot; &lt;&lt; counter;
18:         return 0;
<TT>19: }</TT>
Output: How many hellos?: 2
Hello!
Hello!
Counter is OutPut: 0

How many hellos?: 0
Counter is OutPut: 0
</FONT></PRE>
<P><FONT COLOR="#000077"><B>Analysis:</B></FONT><B> </B>The user is prompted for
a starting value on line 10. This starting value is stored in the integer variable
<TT>counter</TT>. The value of <TT>counter</TT> is tested on line 12, and decremented
in the body of the <TT>while</TT> loop. The first time through <TT>counter</TT> was
set to <TT>2</TT>, and so the body of the <TT>while</TT> loop ran twice. The second
time through, however, the user typed in <TT>0</TT>. The value of <TT>counter</TT>
was tested on line 12 and the condition was false; <TT>counter</TT> was not greater
than <TT>0</TT>. The entire body of the <TT>while</TT> loop was skipped, and <TT>Hello</TT>
was never printed.<BR>
What if you want to ensure that <TT>Hello</TT> is always printed at least once? The
<TT>while</TT> loop can't accomplish this, because the <TT>if</TT> condition is tested
before any printing is done. You can force the issue with an <TT>if</TT> statement
just before entering the <TT>while</TT>:</P>
<PRE><FONT COLOR="#0066FF">if (counter &lt; 1)  // force a minimum value
counter = 1;</FONT></PRE>
<P>but that is what programmers call a &quot;kludge,&quot; an ugly and inelegant
solution.
<H3 ALIGN="CENTER"><A NAME="Heading27"></A><FONT COLOR="#000077">do...while</FONT></H3>
<P>The <TT>do...while</TT> loop executes the body of the loop before its condition
is tested and ensures that the body always executes at least one time. Listing 7.7
rewrites Listing 7.6, this time using a <TT>do...while</TT> loop.</P>
<P><A NAME="Heading28"></A><FONT SIZE="4" COLOR="#000077"><B>Listing 7.7. Demonstrates
do...while loop.</B></FONT></P>
<PRE><FONT COLOR="#0066FF">1:      // Listing 7.7
2:      // Demonstrates do while
3:
4:      #include &lt;iostream.h&gt;

?? 快捷鍵說明

復制代碼 Ctrl + C
搜索代碼 Ctrl + F
全屏模式 F11
切換主題 Ctrl + Shift + D
顯示快捷鍵 ?
增大字號 Ctrl + =
減小字號 Ctrl + -
亚洲欧美第一页_禁久久精品乱码_粉嫩av一区二区三区免费野_久草精品视频
欧美主播一区二区三区| 久久国产精品色婷婷| 99久久国产综合色|国产精品| 亚洲午夜久久久久久久久电影院| 色综合天天视频在线观看| 亚洲精选一二三| 欧美午夜电影网| 美国欧美日韩国产在线播放| 欧美成人国产一区二区| 国产黄色精品网站| 成人欧美一区二区三区小说| 在线观看中文字幕不卡| 午夜精品久久久久久久蜜桃app| 欧美顶级少妇做爰| 久久99热99| 中文字幕亚洲成人| 欧美精品一卡两卡| 狠狠色狠狠色综合系列| 中文字幕在线不卡| 欧美日韩精品综合在线| 国产一区不卡在线| 一区二区三区中文在线| 欧美一区二区三区日韩视频| 国产aⅴ综合色| 亚洲综合精品自拍| 久久伊99综合婷婷久久伊| 成人黄色小视频| 日本亚洲一区二区| 亚洲国产精品av| 91精品在线观看入口| 高清不卡在线观看| 日韩成人一级片| 中文字幕一区二区三区四区| 91精品蜜臀在线一区尤物| 国产东北露脸精品视频| 亚洲成av人片www| 国产欧美精品在线观看| 欧美一区二区三区日韩视频| 成人av网站在线观看| 免费一级片91| 亚洲影视资源网| 日本一区二区三区免费乱视频| 欧美日韩在线播放一区| 国产不卡视频在线播放| 秋霞午夜鲁丝一区二区老狼| 亚洲少妇屁股交4| 精品va天堂亚洲国产| 精品污污网站免费看| 国产99久久久久久免费看农村| 婷婷国产v国产偷v亚洲高清| 中文字幕日韩一区| 久久久国产精品麻豆| 欧美一区三区四区| 91久久国产综合久久| 国产成人av福利| 精品一区二区免费视频| 午夜精品aaa| 亚洲亚洲精品在线观看| 亚洲欧美日韩国产成人精品影院| 久久久午夜电影| 日韩免费高清视频| 91 com成人网| 欧美视频精品在线| 日本韩国欧美在线| 91日韩在线专区| 99久久精品久久久久久清纯| 国产a精品视频| 国产成人日日夜夜| 国产精品资源站在线| 精品在线一区二区| 久草中文综合在线| 欧美在线免费观看亚洲| jizz一区二区| 99精品视频在线免费观看| 成人高清免费在线播放| 粗大黑人巨茎大战欧美成人| 国产精品亚洲一区二区三区在线 | 国产日韩欧美a| 欧美xingq一区二区| 日韩一区二区在线免费观看| 欧美一区二区三区人| 日韩一区二区电影网| 日韩欧美在线影院| 欧美精品一区二区久久久| 精品美女被调教视频大全网站| 日韩免费成人网| 精品国产成人系列| 国产欧美一区二区在线| 国产精品毛片高清在线完整版| 国产精品三级在线观看| 亚洲欧美在线高清| 日韩欧美电影一二三| 日本不卡不码高清免费观看| 国模一区二区三区白浆| 精品一区二区久久| 粉嫩欧美一区二区三区高清影视| 国产成a人亚洲精| 成人h动漫精品| 在线一区二区视频| 91精品国产欧美一区二区成人| 精品少妇一区二区三区在线播放| 久久亚洲一级片| 成人欧美一区二区三区1314| 一区二区三区不卡视频在线观看| 亚洲6080在线| 美女任你摸久久| 成人黄色国产精品网站大全在线免费观看 | 亚洲男人天堂av网| 91女神在线视频| 欧美日韩精品一区二区三区| 日韩一区二区视频在线观看| 久久精品男人的天堂| 亚洲桃色在线一区| 青青草国产精品97视觉盛宴 | 韩国成人在线视频| 成人av在线观| 91 com成人网| 国产精品麻豆一区二区| 亚洲成人在线免费| 国产ts人妖一区二区| 日本乱人伦aⅴ精品| 精品国产区一区| 夜夜精品视频一区二区| 国内精品久久久久影院薰衣草| 日本高清无吗v一区| 2023国产精品| 亚洲国产视频a| 粉嫩欧美一区二区三区高清影视| 欧美日韩1区2区| 中文字幕日韩av资源站| 美日韩一区二区| 欧洲激情一区二区| 国产免费成人在线视频| 免费成人深夜小野草| 色偷偷一区二区三区| 国产午夜亚洲精品羞羞网站| 五月婷婷久久丁香| 91啪亚洲精品| 欧美国产精品一区二区三区| 免费成人美女在线观看.| 色婷婷一区二区| 欧美激情一区二区三区| 美国毛片一区二区| 欧美日韩精品一区二区三区四区| 中文字幕中文乱码欧美一区二区 | 久久先锋资源网| 天天综合色天天综合色h| 99久久综合国产精品| 久久久三级国产网站| 老司机免费视频一区二区三区| 91国产福利在线| 亚洲女性喷水在线观看一区| 国产精品亚洲а∨天堂免在线| 欧美精品日日鲁夜夜添| 亚洲精品国产精华液| 91在线一区二区三区| 欧美激情一区二区三区四区| 国产成人午夜视频| 久久久久久日产精品| 国产真实乱对白精彩久久| 日韩一级完整毛片| 免费国产亚洲视频| 91精品国产日韩91久久久久久| 午夜欧美大尺度福利影院在线看| 欧美亚洲一区二区三区四区| 亚洲激情六月丁香| 日本黄色一区二区| 亚洲午夜免费电影| 欧美日韩一区视频| 天天影视涩香欲综合网| 欧美日韩国产综合一区二区| 亚洲va欧美va天堂v国产综合| 欧美色成人综合| 日本视频一区二区| 日韩欧美中文字幕精品| 国产一区欧美二区| 国产日韩欧美在线一区| 成人午夜视频免费看| 国产欧美视频在线观看| 欧美精品一区二区精品网| 久久精品国产99| 久久久蜜桃精品| av在线播放成人| 亚洲与欧洲av电影| 91精品国产欧美日韩| 久久99精品一区二区三区三区| 久久毛片高清国产| 不卡视频一二三四| 一区二区三区成人在线视频| 6080午夜不卡| 国产毛片精品一区| 国产精品国产三级国产三级人妇 | 亚洲一二三级电影| 91麻豆精品国产91久久久| 久久精品国产在热久久| 国产精品女同互慰在线看| 91久久国产综合久久| 日本特黄久久久高潮| 中文字幕高清一区| 欧美三级电影网|