Mic*_*pen 4 c++ for-loop simplify
是否可以在不使用uint16_t的情况下将此for循环更短或更优雅?当我达到0xFF时有溢出.
for (uint8_t i = 0; i <= 0xFF; i++)
{
// do something
if (i == 0xFF)
break;
}
Run Code Online (Sandbox Code Playgroud)
为了覆盖整个范围,我们只需要在循环体之后进行测试,所以使用do ... while非常适合这里:
uint8_t i = 0;
do {
...
} while (i++ < 0xFF);
Run Code Online (Sandbox Code Playgroud)