• <i id='YPmCP'><tr id='YPmCP'><dt id='YPmCP'><q id='YPmCP'><span id='YPmCP'><b id='YPmCP'><form id='YPmCP'><ins id='YPmCP'></ins><ul id='YPmCP'></ul><sub id='YPmCP'></sub></form><legend id='YPmCP'></legend><bdo id='YPmCP'><pre id='YPmCP'><center id='YPmCP'></center></pre></bdo></b><th id='YPmCP'></th></span></q></dt></tr></i><div id='YPmCP'><tfoot id='YPmCP'></tfoot><dl id='YPmCP'><fieldset id='YPmCP'></fieldset></dl></div>
    <legend id='YPmCP'><style id='YPmCP'><dir id='YPmCP'><q id='YPmCP'></q></dir></style></legend>

        <tfoot id='YPmCP'></tfoot>

        <small id='YPmCP'></small><noframes id='YPmCP'>

        • <bdo id='YPmCP'></bdo><ul id='YPmCP'></ul>

      1. C++ while 和 do while 的区别?

        The difference between while and do while C++?(C++ while 和 do while 的区别?)
          <tbody id='7wHMX'></tbody>

      2. <small id='7wHMX'></small><noframes id='7wHMX'>

              <bdo id='7wHMX'></bdo><ul id='7wHMX'></ul>
              1. <legend id='7wHMX'><style id='7wHMX'><dir id='7wHMX'><q id='7wHMX'></q></dir></style></legend>
                <i id='7wHMX'><tr id='7wHMX'><dt id='7wHMX'><q id='7wHMX'><span id='7wHMX'><b id='7wHMX'><form id='7wHMX'><ins id='7wHMX'></ins><ul id='7wHMX'></ul><sub id='7wHMX'></sub></form><legend id='7wHMX'></legend><bdo id='7wHMX'><pre id='7wHMX'><center id='7wHMX'></center></pre></bdo></b><th id='7wHMX'></th></span></q></dt></tr></i><div id='7wHMX'><tfoot id='7wHMX'></tfoot><dl id='7wHMX'><fieldset id='7wHMX'></fieldset></dl></div>
              2. <tfoot id='7wHMX'></tfoot>

                  本文介绍了C++ while 和 do while 的区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                  问题描述

                  我希望有人解释一下 C++ 中的 while 和 do while 之间的区别

                  I would like someone to explain the difference between a while and a do while in C++

                  我刚开始学习 C++,使用这段代码,我似乎得到了相同的输出:

                  I just started learning C++ and with this code I seem to get the same output:

                  int number =0;
                  
                  while (number<10)
                  {
                  cout << number << endl;
                  number++
                  }
                  

                  和这段代码:

                  int number=0;
                  
                  do
                  {
                  cout << number << endl;
                  number++
                  } while (number<10);
                  

                  在这两种计算中的输出都是相同的.所以好像没什么区别.我试图寻找其他例子,但它们看起来很难理解,因为它包含数学内容和其他我还没有完全学会的东西.此外,我的书对我的问题给出了一种迷幻的答案.

                  The output is both the same in these both calculations. So there seem to be no difference. I tried to look for other examples but they looked way to difficult to understand since it contained mathemetical stuff and other things which I haven't quite learned yet. Also my book gives a sort of psychedelic answer to my question.

                  有没有更简单的例子来说明这两个循环之间的区别?

                  Is there an easier example to show the difference between these 2 loops?

                  我很好奇

                  推荐答案

                  while 循环是一个入口控制循环,即它首先检查条件while(condition){ ...body... } 中,然后执行循环体并不断循环和重复该过程直到条件是假的.

                  The while loop is an entry control loop, i.e. it first checks the condition in the while(condition){ ...body... } and then executes the body of the loop and keep looping and repeating the procedure until the condition is false.

                  do while 循环是一个退出控制循环,即它检查do{...body 中的条件...}while(condition) 在循环体执行之后(do while 循环体中的循环体将始终至少执行一次) 然后再次循环遍历主体,直到发现条件为假.

                  The do while loop is an exit control loop, i.e. it checks the condition in the do{...body...}while(condition) after the body of the loop has been executed (the body in the do while loop will always be executed at least once) and then loops through the body again until the condition is found to be false.

                  希望这有帮助:)

                  例如:在 while 循环的情况下,在这种情况下不会打印任何内容,因为 1 不小于 1,条件失败并退出循环

                  For Example: In case of while loop nothing gets printed in this situation as 1 is not less than 1, condition fails and loop exits

                  int n=1;
                  while(n<1)
                      cout << "This does not get printed" << endl;
                  

                  而在 do while 语句被打印的情况下,因为它现在对条件一无所知,直到它至少执行一次主体,然后因为条件失败而停止.

                  Whereas in case of do while the statement gets printed as it doesn't know anything about the condition right now until it executes the body atleast once and then it stop because condition fails.

                  int n=1;
                  do
                     cout << "This one gets printed" << endl;
                  while(n<1);
                  

                  这篇关于C++ while 和 do while 的区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                  本站部分内容来源互联网,如果有图片或者内容侵犯了您的权益,请联系我们,我们会在确认后第一时间进行删除!

                  相关文档推荐

                  What is inside .lib file of Static library, Statically linked dynamic library and dynamically linked dynamic library?(静态库、静态链接动态库和动态链接动态库的 .lib 文件里面是什么?)
                  How do I load a C DLL from the SXS in Python?(如何从 Python 中的 SXS 加载 C DLL?)
                  Can Cython code be compiled to a dll so C++ application can call it?(Cython 代码可以编译成 dll 以便 C++ 应用程序可以调用它吗?)
                  Delay Loading DLLs(延迟加载 DLL)
                  Throwing C++ exceptions across DLL boundaries(跨 DLL 边界抛出 C++ 异常)
                  Loading a dll from a dll?(从 dll 加载 dll?)
                      <tbody id='c9uf4'></tbody>

                      <i id='c9uf4'><tr id='c9uf4'><dt id='c9uf4'><q id='c9uf4'><span id='c9uf4'><b id='c9uf4'><form id='c9uf4'><ins id='c9uf4'></ins><ul id='c9uf4'></ul><sub id='c9uf4'></sub></form><legend id='c9uf4'></legend><bdo id='c9uf4'><pre id='c9uf4'><center id='c9uf4'></center></pre></bdo></b><th id='c9uf4'></th></span></q></dt></tr></i><div id='c9uf4'><tfoot id='c9uf4'></tfoot><dl id='c9uf4'><fieldset id='c9uf4'></fieldset></dl></div>

                      <small id='c9uf4'></small><noframes id='c9uf4'>

                    1. <tfoot id='c9uf4'></tfoot>

                        <bdo id='c9uf4'></bdo><ul id='c9uf4'></ul>
                          1. <legend id='c9uf4'><style id='c9uf4'><dir id='c9uf4'><q id='c9uf4'></q></dir></style></legend>