什么是时间和做什么? [英] what is while and do while?

查看:108
本文介绍了什么是时间和做什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

什么是时间和做什么

[第二个问题删除,已经在网站上]

解决方案

do ... while - 循环有一个最重要的区别。要找到差异,请参阅文档:

声明(C) [ ^ ]

do-while Statement(C) [ ^ ]


这些是两种类型的控制流技术,我们通过许多项目实现循环。在while和do while之间存在细微差别。



- >如果你满足所提供的条件,你只能进入循环体内。如果你的情况在第一次尝试时被伪造,那么你就不能进入循环。

- >在Do中你的条件是否伪造,但你可以至少进入一次内循环。然后检查每次迭代的条件。对于第一次迭代它不检查给定的条件。



这是一个次要的但是在while和do之间非常显着的区别。


@Jitendra Sabat给出的描述是什么时候和做的同时执行并且是最佳解决方案



一个实时的例子,我可以给予的时间和做的时间是



1)虽然

当我们访问购物中心时,他们首先要彻底检查我们,如果一切正常,那么我们就可以进入。类似于C或任何其他编程语言while首先检查条件,如果一切都很好,那么循环中的代码可以执行。

ex。

  int  i =  6  
while (i< ; 5)
{
// 不执行因为条件失败,6不小于5 。
printf( incrimenting i);
}





2)同时

当我们首先访问购物中心内的商店时,我们购买所有的文章,然后我们出来的安全人员检查我们的账单和内容,如果一切正常。类似地,dowhile将首先让您执行代码,最后检查条件。在dowhile中,无论代码执行至少一次,因为最后检查条件。

ex。

  int  i =  6  

{
// 执行一次,因为在逻辑之前没有检查条件。
printf( incrimenting i);
} while (i< 5)


what is while and do while
[2nd Question Removed, already on Site]

解决方案

while and do...while - loops with one most important difference. To find the difference, please, see the documentation:
while Statement (C)[^]
do-while Statement (C)[^]


These are two types of control flow techniques in which we achieve looping through a number of items.There is a small difference in while and do while.

-> In while you can only get inside body of loop if you satisfy the provided condition.If your condition falsifies at first attempt,then you can't go inside of loop.
-> In Do while whether your condition falsify or not,but you can get inside loop atleast once.Afterwards condition is checked for each iterations.For first iteration it does not check the given condition.

This is a minor but very remarkable difference between while and do while.


The description given by @Jitendra Sabat is what exactly while and do while perform and is optimum solution

One real time example i can give of while and do while are

1)While
When we visit shopping malls they first check us thoroughly and if all is fine then we can make our entry in. Similarly in C or any other programming language "while" first checks for condition and if all is fine only then the code inside the loop can execute.
ex.

int i = 6
while(i<5)
{
    //Wont execute because condition fails, 6 is not less than 5.
    printf("incrimenting i");
}



2)do while
When we visit shops inside shopping mall first we buy all the articles and then we are coming out the security person checks our bills and contents if all is fine. Similarly "dowhile" will first let you execute your code and at last it checks for conditions. In "dowhile" no matter what the code executes at least once as condition is checked at the last.
ex.

int i = 6
do
{
    //Executes once as no condition is checked prior to logic.
    printf("incrimenting i");
}while(i<5)


这篇关于什么是时间和做什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆