do {循环体} while(1); 是什么意思 while(1) 什么意思 while(i--)什么意思?

do\uff08\uff09 while\uff08\uff011\uff09\u662f\u5565\u610f\u601d

1 eof()\u51fd\u6570\u4e3a\u5224\u65ad\u662f\u5426\u5230\u6587\u4ef6\u5c3e\u51fd\u6570\uff0c\u5f53\u5230\u5c3e\u65f6eof()\u51fd\u6570\u4e3a\u771f\uff0c\u4e0d\u5230\u5c3e\u65f6\u51fd\u6570\u503c\u4e3a\u5047\u3002\r\n2 do While\u662f\u5f53\u578b\u5faa\u73af\uff0c\u5f53\u6761\u4ef6\u6ee1\u8db3\u65f6\u6267\u884c\u5faa\u73af\u4f53\uff0c\u6761\u4ef6\u4e0d\u6ee1\u8db3\u65f6\u9000\u51fa\u5faa\u73af\u3002\r\n\u6240\u4ee5 not eof()\u4e3a\u771f\u4ee3\u8868\u6ca1\u5230\u6587\u4ef6\u5c3e\uff0c\u6240\u4ee5\u6b64\u53e5\u4e3a\u6ca1\u5230\u6587\u4ef6\u5c3e\u5c31\u6267\u884c\u5faa\u73af\u4f53\u3002

while(1)\u5176\u4e2d1\u4ee3\u8868\u4e00\u4e2a\u5e38\u91cf\u8868\u8fbe\u5f0f\uff0cwhile(1) \u8868\u793a\u65e0\u9650\u5faa\u73af\uff0c\u9664\u975e\u4f60\u8bbe\u7f6ebreak\u7b49\u7c7b\u4f3c\u7684\u8df3\u51fa\u5faa\u73af\u8bed\u53e5\u5faa\u73af\u624d\u4f1a\u4e2d\u6b62
while(i--)\u5176\u4e2di\u662f\u4e00\u4e2a\u53d8\u91cf\uff0c\u56e0\u6b64\u8868\u8fbe\u5f0fi--\u6709\u4e0d\u540c\u7684\u503c\uff0c\u4f9d\u6b21\u9012\u51cf\uff0ci--\u662f\u5148\u53d6\u503c\u540e\u51cf\uff0c--i\u5148\u52a0\u540e\u53d6\u503c,\u6240\u4ee5i--\u7684\u503c\u540c\u672a\u6267\u884c\u8be5\u81ea\u51cf\u8fd0\u7b97\u65f6\u7684i\u76f8\u7b49\u3002

\u6269\u5c55\u8d44\u6599\uff1awhile(1) \u8868\u793a\u65e0\u9650\u5faa\u73af\u3002
while\u7684\u8bed\u6cd5\u683c\u5f0f\u4e3a \uff1a
while(condition){//do something 1}//do something 2
condition \u4e3a\u5faa\u73af\u6761\u4ef6\uff0c\u6bcf\u6b21\u5224\u65adcondition\u662f\u5426\u4e3a\u771f\uff0c\u4e3a\u771f\u65f6\u6267\u884cwhile\u5faa\u73af\u4f53\u4e2d\u7684\u8bed\u53e5\u5757(\u4ee3\u7801\u4e2d\u57571)\uff1b\u4e3a\u5047\u65f6\u7ed3\u675f\u5faa\u73af\uff0c\u6267\u884c\u540e\u7eed\u8bed\u53e5\uff08\u4ee3\u7801\u4e2d\u57572\uff09\u3002
\u8fd9\u91cccondition\u4e3a1 \u8868\u793a\u6761\u4ef6\u6c38\u8fdc\u4e3a\u771f\uff0c\u4e00\u76f4\u6267\u884c\u5faa\u73af\u4f53\u5185\u8bed\u53e5\u3002\u4e3a\u4e86\u7ed3\u675f\u5faa\u73af\uff0c\u53ef\u4ee5\u5728\u5faa\u73af\u4f53\u5185\u6ee1\u8db3\u67d0\u4e9b\u7279\u5b9a\u6761\u4ef6\u4f7f\u7528break\u8df3\u51fa\u5faa\u73af\u3002
\u5982\u4e0b\uff1a
while(1){//do somethingif(condition){break;}}
\u53c2\u8003\u8d44\u6599\uff1a\u767e\u5ea6\u767e\u79d1-while

无限循环。
while 只有为假才跳出循环。
在循环体内用if 语句判断是否达到条件,用break 调出循环。
相同的还有一个while {},这个与上面那个不同的是,一个是先判断再执行,一个是先执行,再判断。
通常用于消息循环用。或者是循环取值和阻滞状态。

此循环无限执行,因为while里面的1 是个常量,其值恒为真,所以会死循环

一直循环的意思。这个是一个死循环。单片机程序里能用到。

就是不停的跑这里面,等待其他条件触发才能出去

扩展阅读:do while循环中while n ... do while用法举例 ... do while至少循环一次 ... 如何退出while 1 循环 ... xbox series x ... while 0 循环还执行吗 ... do while循环结束 ... do-while语句的循环体 ... do while循环语句用法 ...

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