是的,通常,基本上.一个for循环,写的
for (a; b; c) { ... }
Run Code Online (Sandbox Code Playgroud)
可以改写为
a;
while (b) { ...; c; }
Run Code Online (Sandbox Code Playgroud)
请注意,这并未考虑作用域和此类问题,因为当您将for转换为while时,无法在C++语法中精确编写作用域.
但是,在下面,for循环实际上是一系列语句和(条件)gotos:
{
a;
goto test;
body:
...;
c;
test:
if (b) goto body:
}
Run Code Online (Sandbox Code Playgroud)
除了所有它都在汇编代码中.