until可以退出while循环却不能退出for循环

until可以退出while循环却不能退出for循环

Content #

用GDB调试下面的两个循环,为什么until命令可以退出while循环,却不能退出 for循环?

int i = 9999;
while (i--) {
  ...
}

int i;
for (i = 0; i < 10; i++) {
  ...
}

From #

In fact, what until really does is execute until it reaches a machine instruction that has a higher memory address than the current one, rather than until it reaches a larger line number in the source code.

GCC编译for循环时,会把循环条件放在循环体的底部,因此,for循环体中的下一条语句是循环条件,从源角度来看,在for循环中使用until后又从新回到了 for语句上。