C GOTO使用示例

时间:2023-03-10 01:58:26
C GOTO使用示例

GOTO虽然会破坏程序的结构,使用代码可读性变差,但是GOTO依然还是有可用的地方

#include <stdio.h>
#include <stdbool.h>

int main()
{
  bool a = false;

step1:
  if (a)
    goto step2;
  while (true)
  {
    printf("while out\n");
    while (true)
    {
      printf("while inner\n");
      a = true;
      goto step1;
    }
  }

step2:
  return 0;
}