我想预先递增变量的赋值(预递增值大于 1)?
I want to pre-increment an assignment to a variable (pre-increment by value more than 1)?
我想在 for 循环中预先递增值赋
值for (int x=0; x<100; x+=increase){
// loop operation here
}
上面的代码 post 增加了值,但我想预先递增它。我知道我可以使用++i
语法预递增 1,但是有没有办法通过变量赋值预递增。
听起来你有两个误解。
x += y
已经"等价"于预递增,因为根据定义,x += 1
与++x
相同。 (关键是x += y
的值是 x 的更新值,就像++x
的值是更新的值一样。它是后增量表单x++
,除了 1 之外,没有添加增量的确切等效项。- 当你写
for(x = 0; x < 100; x += increase)
时,你不会立即使用表达式x += increase
的值,所以你使用前增量还是后增量形式并不重要。
如果您希望循环以increase
而不是 0 的初始值开头,只需编写
for(x = increase; x < 100; x += increase)
相关文章:
- 如何创建一个CMake变量,除非显式重写,否则使用默认值
- 将成员变量添加到共享库中的类中,不会破坏二进制兼容性吗
- 将数组的地址分配给变量并删除
- 为"adjacent"变量赋值时出现问题
- enum是C++中的宏变量还是整数变量
- 在全局变量中保存类的实例以重新创建类(创建"backup")
- 用C++中的一个变量定义一个常量
- 具有奇怪重复模板模式的派生类中的成员变量已损坏
- 你能重载对象变量名本身返回的内容吗
- 内置函数可查看CPP中的成员变量
- 是否可以初始化不可复制类型的成员变量(或基类)
- 尝试通过多个向量访问变量时,向量下标超出范围
- 试图让变量检查数组中的某些内容
- 如果变量数据包含大于 vector 所有元素的整数,则仅在视觉工作室上接收"矢量下标超出范围"?
- 为什么 UInt64 变量不能包含大于 UInt32::Max 的值?
- 我想预先递增变量的赋值(预递增值大于 1)?
- 当运算符尝试输入大于变量可以包含的值>>会发生什么情况?
- C++ 大于堆栈的变量(堆栈溢出)
- 变量的范围大于for循环,为什么它不改变值
- timeGetTime()开始变量大于结束变量