+ 12
What is the use of goto statement in C or C++
I want to know how to make use of "goto statement" in my programs and i can't find anything about it on sololearn so i want help from you guys.
3 Réponses
+ 14
The goto statement is a jump statement which is sometimes also referred to as unconditional jump statement. The goto statement can be used to jump from anywhere to anywhere within a function.
CODE 👇👇👇
#include <stdio.h>
int main() {
int sum=0;
for(int i = 0; i<=10; i++)
{
sum = sum+i;
if(i==5){
goto addition;
}
}
addition: printf("%d", sum);
return 0;
}
OUTPUT 👉15
--------------------------------------------------------
hope you got the answer
+ 6
break and continue statements within loops are other types of jump statements.
+ 4
sams answer is correct but remember that the use of “goto” is not recommeded and thats the reason you cant find anithing about it.
problably is still there for old legacy code.