具有双重条件的for循环 [英] for loops with dual conditions

查看:110
本文介绍了具有双重条件的for循环的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

为什么在for循环的双重条件中最右边的条件只考虑

因此使用其他条件

例如

for(i = 0,j = 0; i< 40,j< 100; i ++,j ++)

{

}


i和j增加到100

Why is that the rightmost condition in a for loop''s dual condition only
taken into account so whats the use of the other condition
eg
for(i=0,j=0;i<40,j<100;i++,j++)
{
}

i and j are incremented to 100

推荐答案

termin写于16/07/05:
termin wrote on 16/07/05 :
为什么只考虑for循环的双重条件中最右边的条件,因此使用其他条件

例如
(i = 0,j = 0; i <40,j <100; i ++,j ++)
{

}
我和j增加到100
Why is that the rightmost condition in a for loop''s dual condition only
taken into account so whats the use of the other condition

eg
for(i=0,j=0;i<40,j<100;i++,j++)
{

}

i and j are incremented to 100




因为C语言是这样定义的。在退出条件表达式中仅计算最右边的

表达式。使用逻辑

运算符,不要在这里使用逗号运算符。


for(i = 0,j = 0; i <40 && j< 100; i ++,j ++)

{

}


-

Emmanuel

C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html

C库: http://www.dinkumware.com/refxc.html


很明显,你的代码不符合原始规格。

你用湿面条判处30睫毛。

- Jerry Coffin in alcc ++



Because the C language is defined like that. Only the rightmost
expression is evalued in the exit condition expression. Use the logical
operators, and don''t use the comma operator here.

for(i = 0, j = 0; i < 40 && j < 100; i++, j++)
{
}

--
Emmanuel
The C-FAQ: http://www.eskimo.com/~scs/C-faq/faq.html
The C-library: http://www.dinkumware.com/refxc.html

"Clearly your code does not meet the original spec."
"You are sentenced to 30 lashes with a wet noodle."
-- Jerry Coffin in a.l.c.c++


" termin" <分贝***** @ gmail.com>在消息中写道

news:11 ********************* @ g43g2000cwa.googlegro ups.com ...
"termin" <db*****@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
为什么在for循环的最重要条件'的双重条件只考虑
因此使用其他条件

例如
for(i = 0,j = 0; i <40,j <100; i ++,j ++)
{

}

我和j增加到100
Why is that the rightmost condition in a for loop''s dual condition only
taken into account so whats the use of the other condition
eg
for(i=0,j=0;i<40,j<100;i++,j++)
{
}

i and j are incremented to 100




因为在C中,形式为a,b的表达式求值为最后一个,b。

如果你想要同时采用这两个条件在帐户中将它们变成一个单独的一个,没有昏迷。


Alex



Because in C, an expression of the form a, b evaluates to the last one, b.
If you want both conditions to be taken in account transform them into a
single one, without coma.

Alex


termin写道:
termin wrote:
为什么只考虑for循环的双重条件中最右边的条件
考虑到使用其他条件

例如
for(i = 0,j = 0; i< 40,j< 100; i ++,j ++)
Why is that the rightmost condition in a for loop''s dual condition only
taken into account so whats the use of the other condition
eg
for(i=0,j=0;i<40,j<100;i++,j++)




for(i = 0 ,j = 0; i <40& j < 100; i ++,j ++)

查找逗号运算符在你的C书中了解为什么只有第二个

你的两个测试有助于你的循环控制。

-

Richard Heathfield

Usenet是一个奇怪的地方 - dmr 29/7/1999
http://www.cpax.org.uk

邮件:rjh在上述域名



for(i = 0, j = 0; i < 40 && j < 100; i++, j++)
Look up "comma operator" in your C book to understand why only the second of
your two tests contributed to your loop control.
--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
mail: rjh at above domain


这篇关于具有双重条件的for循环的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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