ChinaUnix.net
相关文章推荐:

do while

// setup int status = 0; do { // preconditions status = doSomething(); if (status) break; status = doSomethingElse(); if (status) break; // computation status = doWhatYouWantedToInTheFirstPlace(); } while (false); // cleanup return status;

by 南无小和尚 - C/C++ - 2009-03-05 14:14:01 阅读(1546) 回复(8)

相关讨论

do..while 是重复叙述的循环,可以分成两种模式。 最单纯的就是只有 while 的循环。用来在指定的条件内,不断地重覆指定的步骤。语法如下 while (expr) { statement } 其中的 expr 为判断的条件,通常都是用逻辑运算符号 (logical operators) 当判断的条件。而 statement 为符合条件的执行部分程序,若程序只有一行,可以省略大括号 {}。 下例很有趣,要电脑的浏览器出现十次 "以后不敢了" 的字符串,前面并加上数字,表示说了...

by 剑心通明 - php文档中心 - 2008-04-17 18:22:09 阅读(978) 回复(0)

fpin=fopen("1.txt","w"); fpout=popen("/bin/ls","r"); while(fgets(line,MAXLINE,fpin)!=NULL) { if(fputs(line,fpout)==EOF) printf("error"); } 是正确的 而 fpin=fopen("1.txt","w"); fpout=popen("/bin/ls","r"); do { if(fgets(line,MAXLINE,fpin)==NULL) printf("error"); }while(fputs(line,fpout)!=EOF); 错误那? 下面的那一个是死循环; [ 本帖最后由 mu_mu8309 于 2006-12-1 15:04 编...

by mu_mu8309 - C/C++ - 2006-12-04 08:14:42 阅读(1143) 回复(4)

一直觉得do {} while (false)在写宏时比较有用,但刚刚看到有人这么用: [CODE] do { if (first_condition) break; if (second_condition) break; if (outer_condition){ if (inner_conditio){ break; } } .... } while (false); [/CODE] 据说这样写可以不用goto,但个人感觉并不比用goto好,而且还多了一层嵌套,大家怎么认为呢?或者作者还有什么别的用意?

by bidongliang - C/C++ - 2009-07-07 16:29:07 阅读(14105) 回复(55)

main() { int count=1,sum=0; do { sum=sum+count; count++; } while(count<=100) printf("sum=%d\n",sum); } [root@mylinux c]# gcc dowhile.c dowhile.c: In function `main': dowhile.c:9: error: syntax error before "printf"

by xi2008wang - C/C++ - 2007-11-26 18:07:34 阅读(1663) 回复(4)

[code]#include int main() { int get; do { printf ("Press X and x to exit. any other key continue\n"); get = getchar(); }while(get != 'x' || get != 'X'); // 这是若是没有“||”,就不会有问题,现在似乎执行了两次{}里的内容,不知道是为什么 }[/code]

by liec - C/C++ - 2008-03-27 13:29:24 阅读(1253) 回复(7)

如题,把一个宏定义成do {} while(0); 到底有什么作用。 请教。

by yjh777 - 内核/嵌入技术 - 2005-12-20 10:52:43 阅读(22312) 回复(29)

有一个文件内容如下: PID 28606 197 26483 3036 28488 24802 14657 24743 166 181 202 162 165 232 169 Total: 我想当第一列的数值相加,除去行内容为pid和Total,要用dowhile循环!

by xinruinet - Shell - 2005-12-12 16:40:32 阅读(1710) 回复(7)

while true do 。。。。 。。。。 done 如何结束循环的。返回0则是true吗?我写了一个死循环。 特别伤心。 //cry

by text2002 - Shell - 2004-04-30 21:24:04 阅读(2447) 回复(1)

听说有do {...break...} while (false) 这种写法, 但是ANSI C好像只允许在switch语句中使用break? [ 本帖最后由 dl1987 于 2009-7-22 10:48 编辑 ]

by dl1987 - C/C++ - 2009-10-02 00:52:22 阅读(22468) 回复(30)

看到很多宏定义里边都有类似的结构,比如: #define err_abort (code, text) do { \ fprintf (stderr, "%s at \"%s\":%d: %s\n", \ text, __FILE__, __LINE__, strerror (code)); \ abort (); \ } while (0) 这里用while只执行一次,个人觉得do...while(0)仅仅是把里边的语句封装到一个代码块而已,并无他用。 是不是这样子的?

by zwylinux - C/C++ - 2007-06-15 13:12:11 阅读(1782) 回复(17)