关系运算符外部循环和条件.. [英] Relational operator outside loops and conditionals..

查看:80
本文介绍了关系运算符外部循环和条件..的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述




这是一个非常基本的问题。


如果有关系运营商的声明会怎样? />
外面是,for或者条件?


这样的东西......


..

..

..

state == 2;

..

..


这句话会被忽略(或者被忽略)吗?


谢谢,

迪帕克

Hi,

This is a very basic question.

What will happen if there is a statement with a relational operator
outside while, for, or if conditions?

Something like this...

..
..
..
state == 2;
..
..

Will the statement be ignored (or as good as ignored) all the times?

Thanks,
Deepak

推荐答案

Janus说:
Janus said:



这是一个非常基本的问题。


如果有关系运营商的声明

外面会发生什么,或者条件?


这样的东西...








州== 2;






Will声明一直被忽略(或者被忽略)?
Hi,

This is a very basic question.

What will happen if there is a statement with a relational operator
outside while, for, or if conditions?

Something like this...

.
.
.
state == 2;
.
.

Will the statement be ignored (or as good as ignored) all the times?



在这种情况下,假设状态是它看起来的样子,编译器很可能完全忽略它虽然一个好的编译器可能会对它进行诊断,但是代码没有效果。或者其他类似的东西。


但如果你有:


state == function();


这将是另一回事,因为function()可能有副作用。


-

Richard Heathfield

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

电子邮件:rjh在上面的域名(但显然放弃了www)

In this case, assuming ''state'' is what it appears to be, the compiler is
very likely to ignore it completely, although a good compiler will probably
diagnose it - "code has no effect" or something along those lines.

But if you had:

state == function();

that would be a different matter, since function() may have side effects.

--
Richard Heathfield
"Usenet is a strange place" - dmr 29/7/1999
http://www.cpax.org.uk
email: rjh at above domain (but drop the www, obviously)





Janus在08/09/06 12:18写道:


Janus wrote On 08/09/06 12:18,:




这是一个非常好的基本问题。


如果有关系运营商的声明

在某个时间段内,在某个条件下,或在条件允许的情况下会发生什么?


这样的东西...








state == 2;






语句是否会被忽略(或者被忽略)所有次?
Hi,

This is a very basic question.

What will happen if there is a statement with a relational operator
outside while, for, or if conditions?

Something like this...

.
.
.
state == 2;
.
.

Will the statement be ignored (or as good as ignored) all the times?



计算表达式,并放弃

评估的结果。编译器可能(或可能不)

通知评估对程序的行为没有任何影响,然后决定消除它。

如果评估没有效果,则无法进行

程序来发现它是否被执行。


关系运营商没什么特别的

看待。以下是其他一些需要思考的表达方式:


x + y;

c? x:y;

x;


....当然还有


州++ == 2;


-
Er ******** *@sun.com

The expression is evaluated, and the result of the
evaluation is discarded. The compiler may (or may not)
"notice" that the evaluation makes no difference to the
behavior of the program, and then decide to eliminate it.
If the evaluation has no effect, there is no way for the
program to discover whether it was or was not performed.

There''s nothing special about the relational operators
in this regard. Here are some other expressions to ponder:

x + y;
c ? x : y;
x;

.... and, of course

state++ == 2;

--
Er*********@sun.com


非常感谢您的回复。

我使用的是枚举值右边,==实际上是一个错字

并没有解决我的问题。所以我只是很好奇。


再次感谢,

迪帕克

Eric Sosman写道:
Thanks a lot for the reply.
I was using an enum value on Right hand side, and the == was a typo
actually and was not solving my issue. So I was just curious.

Thanks once again,
Deepak
Eric Sosman wrote:

Janus写道08/09/06 12:18,:
Janus wrote On 08/09/06 12:18,:




这是一个非常基本的问题。


如果有一个关系运营商的声明

在某个时间段内,某个时间段或条件下会发生什么?


这样的东西...








州== 2;






是否会忽略该陈述(或作为好像被忽略了)所有的时间?
Hi,

This is a very basic question.

What will happen if there is a statement with a relational operator
outside while, for, or if conditions?

Something like this...

.
.
.
state == 2;
.
.

Will the statement be ignored (or as good as ignored) all the times?



计算表达式,并放弃

评估的结果。编译器可能(或可能不)

通知评估对程序的行为没有任何影响,然后决定消除它。

如果评估没有效果,则无法进行

程序来发现它是否被执行。


关系运营商没什么特别的

看待。以下是其他一些需要思考的表达方式:


x + y;

c? x:y;

x;


......当然还有


州++ == 2;


-
Er ********* @ sun.com


这篇关于关系运算符外部循环和条件..的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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