If you want to go back in code, you usually end up thinking about goto
, however the use of the droplet for any program larger than a functionality test is not recommended or even constantly hated, because the droplet breaks the linearity that a program should have when it is read by a human, generating the Spaghetti code that makes everything more complicated to understand, maintain and adapt for use in more places, basically, is a bad practice not only of programming, as for you and everyone who are reading your code, what you need is not of GOTO, after all, not programming in Assembly, what you need is simply function, as modular as possible.
A very simple way to illustrate this is to imagine the following code where you need to ask for a number:
#include <stdio.h>
#include <windows.h>
main(){
pontoInicial:
int i;
printf("\nDigite um numero: ");
scanf("%i", &i);
printf("%i\n", i);
system("pause");
//Muito código depois e você precisa voltar para pedir o número novamente
//e rodar o código a partir dele apenas se usaria com o checkpoint feito anteriormente
goto pontoInicial;
}
But this is very dirty code and it’s easy to imagine that it doesn’t work in the long run, much less for large programs, so it’s easy to create a function to do this and return what you want (or void without Return if you don’t need to):
#include <stdio.h>
#include <windows.h>
int retornaNumero(){
int temp;
printf("\nDigite um numero: ");
scanf("%d", &temp);
printf("%d\n", temp);
system("pause");
return temp;
}
main(){
int i = retornaNumero();
//Assim as coisas ficaram muito mais simples e você pode usar quaaantas vezes quiser e o
//código continua seguindo seu fluxograma de maneira correta e tudo fica mais limpo e modular
}
Function useful and modularization of the code are very important for maintenance and ease of reading, highly recommend trying to do this with your code, and beware of forcing recursions
Ever tried to modularize your code? Maybe it’s what you need, so I understand you have a
main
with more than 1200 lines is this?– Danizavtz
Yes, I have a main with more than 1200 lines, and at this point where I need it to go back, I need it to go through the whole code again after line 250, for example
– Larissa Mapa
Post something compilable, even if it’s not the whole program
– arfneto