开发者

double while, new feature in C++? [closed]

As it currently stands, this question is not a good fit for our Q&A format. We expect answers to be supported by facts, references, or expertise, but this question will likely solicit debate, arguments, polling, or extended discussion. If you feel that this question can be improved and possibly reopened, visit the help center for guidance. Closed 11 years ago.

I found that this compiles in Microsoft Visual C++ 20开发者_如何学Python10.

void main()
{
    int i=9;
    while (i>4)
    {
        i--; 
    }
    while (i>6);
}

Probably not.. the second while does not seems to have an effect


Your

while (i>6);

does not have any effect. It's just a loop with an empty body:

while (i>6)
  ;


There is nothing unusual about it. It's two while statements, except the other one has an empty body. The bigger problem is void main.


You have two separate while loops here. The second just has an empty body. Reformat to:

int i=9;
while (i>4)
{
    i--; 
}

while (i>6)
    ;

...and it might make more sense. In this case, i is 4 upon entry to the second loop, so the second loop never executes.


while (i>6); is no new feature, it simply says that while i is greater than 6 it should execute an empty statement ;.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜