Search
 
SCRIPT & CODE EXAMPLE
 
CODE EXAMPLE FOR C

goto statement in c

#include <stdio.h>

// The goto statement is known as jump statement in C.
// goto is used to transfer the program control to a predefined label.
// Try to avoid it because it as much as possible because it's used to alter-
// -the sequence of normal sequential execution and making a small mistake
// lead to endless iterations.

int main()
{
	int i = 0;
    repeat_from_here:		// the label ( destination )
    	printf("%d ",i++);
    if( i <= 10 )				// Until the condition is satisified
    	goto repeat_from_here;	// the control will jump to the label ( source )
	return 0;
}
 
PREVIOUS NEXT
Tagged: #goto #statement
ADD COMMENT
Topic
Name
2+5 =