while (x=0)与while (x==0)两条语句的循环条件有何区别? while(x)括号中填x==0与x=0的区别

while (x=0)\u4e0ewhile (x==0)\u4e24\u6761\u8bed\u53e5\u7684\u5faa\u73af\u6761\u4ef6\u6709\u4f55\u533a\u522b?

1\u3001while
(x=0)

\u76f8\u5f53\u4e8e\u5982\u4e0b\u8bed\u53e5

x
=
0
//\u6709\u4e00\u4e2a\u8d4b\u503c\u64cd\u4f5c

while
(x)
//\u7136\u540e\u8ba9x\u7684\u503c\u548c0\u505a\u6bd4\u8f83\uff0c\u5982\u679c\u662f0\u5219\u4e0d\u6267\u884c\u5faa\u73af\u4f53\uff0c\u5982\u679c\u975e0\u5219\u6267\u884c\u5faa\u73af\u4f53\u3002

2\u3001while
(x==0)
\u662f\u8ba9\u53d8\u91cfx\u4e0e0\u8fdb\u884c\u6bd4\u8f83\uff0cx\u7684\u503c\u5982\u679c\u662f0\u5219\u6267\u884c\u5faa\u73af\u4f53\uff0c\u5982\u679c\u975e0\u5219\u6267\u884c\u5faa\u73af\u4f53\u3002

3\u3001\u56e0\u6b64\uff0c\u4e24\u8005\u4e0d\u4ec5\u5728\u4e8e=\u548c==\u7684\u533a\u522b\uff0c\u524d\u8005\u662f\u8d4b\u503c\u8fd0\u7b97\u7b26\uff0c\u540e\u8005\u662f\u5173\u7cfb\u8fd0\u7b97\u7b26\uff0c\u540c\u65f6\u5faa\u73af\u6761\u4ef6\u4e5f\u4e0d\u4e00\u6837\u3002

x=0\u662f\u8d4b\u503c\uff0c\u53ef\u4ee5\u62c6\u6210\u4e24\u53e5\uff0cint
x,x=0,while\uff08x\uff09\uff0cx\u4e3a\u96f6\uff0c\u6761\u4ef6\u4e3a\u5047\uff0cwhile\u7ed3\u675f\u3002
x==0\u662f\u5224\u65ad\u8bed\u53e5\uff0c\u5f53x\u4e3a\u96f6\u65f6\uff0c\u6761\u4ef6\u4e3a\u771f\uff0cwhile\u7ee7\u7eed\u3002

  1、while (x=0)
  相当于如下语句
  x = 0 //有一个赋值操作
  while (x) //然后让x的值和0做比较,如果是0则不执行循环体,如果非0则执行循环体。

  2、while (x==0) 是让变量x与0进行比较,x的值如果是0则执行循环体,如果非0则执行循环体。

  3、因此,两者不仅在于=和==的区别,前者是赋值运算符,后者是关系运算符,同时循环条件也不一样。

x=0是赋值,可以拆成两句,int x,x=0,while(x),x为零,条件为假,while结束。
x==0是判断语句,当x为零时,条件为真,while继续。

第一个循环的循环体永远也不会被执行。因为循环条件为x=0,先把0赋值给x,赋值运算符的返回值即为0,在C/C++中,0即为假。
第二个呢是一个逻辑表达式,只要x为0循环就可以执行。

while(x = 0)//赋值语句 结果是0,表示判断代表假
while(x == 0)//布尔语句 结果为真

一个是把0赋给变量x,一个是判断x是否等于0,是不一样的,希望好好理解一下。

扩展阅读:锂电池wh公式 ... while doing ... 100wh一般多少毫安 ... honored 中文翻译 ... who is 是什么意思 ... as soon as什么意思 ... point to the window ... while e 是什么意思 ... point to the door ...

本站交流只代表网友个人观点,与本站立场无关
欢迎反馈与建议,请联系电邮
2024© 车视网