c - for循环到while循环+附加条件

标签 c loops

我有一个与此类似的循环。

int total1, total2;
for (total1 = fsize(myfile);;) {
    total2 = fsize(myfile);
    ...
    ...
    total1 = total2;
}

我想做的是将其转换为 while 循环,并在结束循环之前检查额外条件。

我想做这样的事情:

while((total1 = fsize(myfile)) && input = getch() != 'Q') {
    total2 = fsize(myfile);
    ...
    total1 = total2;
}

谢谢

最佳答案

for 循环的“初始化”部分 total1=fsize(myfile) 已成为 while 循环中测试的条件的一部分。这就是你的意图吗??

你确定你不想要这个吗...

total1 = fsize(myfile);

while((input = getch()) != 'Q') {
  total2 = fsize(myfile);
  ...
  total1 = total2;
}

关于c - for循环到while循环+附加条件,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3294833/

相关文章:

c++ - 打印引用类的指针地址

c - WIN32在套接字函数arg中发送数据错误

c - 从 C 中的输入文件扫描直到到达某个字符 (#)?

c - 双重免费或损坏(fasttop)错误c

c - libcurl c,超时和成功传输

c - C程序环形缓冲区中的错误

java - for 循环中 if 语句中的 return 语句之后会发生什么

bash - 如果循环将输出发送到管道,则重置全局变量

c - 测试输入值类型的函数

loops - 从 Common Lisp 中的嵌套循环返回