Return to beginning of condition when requested

1

I can not use function, I wanted to know how to go back to a certain line of code when the number 0 is pressed, for example:

system(color 7);
printf("Teste");
printf("Teste01");
printf("Pressione 0 para reiniciar");
scanf("%d", &jog);

Now how do I if I enter 0, the run back to the system() line? With function would be easy, but can not use then how do I do?

    
asked by anonymous 12.06.2015 / 19:21

3 answers

3

Although not the best option, one option is goto .

voltaAqui:
... código
goto voltaAqui;
    
12.06.2015 / 19:24
2

You can put the code inside a loop and check if the value of the variable jog is different from 0. If it is, you break the loop:

int jog;

while(1){

  // código...

  printf("Pressione 0 para reiniciar");
  scanf("%d", &jog);

  if(jog) break;
}
    
12.06.2015 / 19:28
2
for (;;) {
    /* codigo */
}

or

while (1) {
    /* codigo */
}

or

do {
    /* codigo */
} while (1):
    
12.06.2015 / 19:30