如何让" I + = X"工作原理"我++ QUOT ;? [英] how to make "i+=x" works as "i++"?

查看:142
本文介绍了如何让" I + = X"工作原理"我++ QUOT ;?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下code

int i=0;
while(i<10) {
   printf("%d\n", i++);
}

等同于

int i=0;
while(i<10) {
   printf("%d\n", i); i++;
}

但下面code

But the following code

int i=0;
while(i<10) {
   printf("%d\n", i+=2);
}

等同于

int i=0;
while(i<10) {
   i+=2; printf("%d\n", i);
}

如何使它相当于

int i=0;
while(i<10) {
   printf("%d\n", i); i+=2;
}

我++

推荐答案

好奇至于如何努力,我会打的建议那样明显的东西为:

Curious as to how hard I'll be hit for suggesting something as obvious as:

for(int i = 0; i < 10; i += 2) {
    printf("%d\n", i);
}

这篇关于如何让&QUOT; I + = X&QUOT;工作原理&QUOT;我++ QUOT ;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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