如何跳转到代码的开头?

我正在制作一个程序,要求用户输入一个输入。 如果用户输入输入,则显示输入,然后完成程序。 如何让程序从头开始? 我的代码是这样构建的:(只显示构建而不是代码本身)

please enter user input: while (x != y) { if ( x == y ) { printf("printing something"); } else if (x > y ) { printf("printing something"); } else { printf("printing something"); } } 

 int main(void) { int num = 0; while( 1 ) { printf("This is a game to find the password. Start this game by trying to guess it with numbers from 1 - 100. The program will tell you if you are close or not.\n"); num = 0; // reset the num back to zero while (num != 65) { printf("please enter a number:\n"); num = GetInt(); if (num == 65) { printf("Nice!!\n"); break; // exit the while (num != 65) } else if (num > 50 && num < 60 ) { printf("almost there! go higher!\n"); } } } } 

如果你不介意使用goto

 HERE: please enter user input: while (x!= y) { if ( x == y ) { printf("printing something"); } else if (x > y ) { printf("printing something"); } else { printf("printing something"); } goto HERE; } 

在这个例子中,你可以看到你永远不会打破。 你必须使用
仔细goto

编辑:

上面的代码有错误。 为了进入while循环x!=y 。 但是之后
你检查x==y ,它总是false 。 所以:

 HERE: please enter user input: while (true) { if ( x == y ) { printf("printing something"); break; } else if (x > y ) { printf("printing something"); } else { printf("printing something"); } goto HERE; } 

编辑2:

你只有一个 while循环

 int num; //your code here HERE: num = GetInt(); while(true) { if (num == 65) { printf("Nice!!\n"); break; } else if (num > 50 && num < 60 ) } else if (something ) something } . . . else{ something } goto HERE; } 

瓦尔特