The below code can be an alternative to a for
loop. You just need to take care of all parts like initialization, condition, iteration count, etc.
int i=0;
abc: i++;
if(i<10){
printf("i is %d\n", i);
goto abc;
}
When a for
loop is compiled, the assembler uses goto-like statements to generate assembly code for a loop(for, while). It is not, however, advisable to use goto
as readability of code will be low and it can also be harmful in some cases. So, we should not use it.
solved Is this a correct alternative to a for loop?