The nature of the goto statement

 

 

_CRT_SECURE_NO_WARNINGS #define 
#include <stdio.h> 
#include <stdlib.h> 
#include <WINDOWS.H> 
void MAIN1 () { 
	// Continue satisfy all the conditions for selecting only for circulation, you can jump this execution, continue to the next round of the cycle cycle 
	// break for selecting a satisfied condition, and only for the cycle switch, you can jump out of the current round of circulation, continue round the back of the loop 
	// goto can jump more than layer nested loops, for, while, dowhile essentially achieved with goto statement, goto statement Comparative bottom 

	// preceding statement statement label identifier is not an integer, the identifier is not a variable, not print 
	goto A2; // goto skip A1 
A1: the printf ( "Hello World"); // statement that is an identifier A1 
A2: the printf ( "Hello World"); 
	getchar (); 
} 
void MAIN2 () { 
A1: the printf ( "Hello World" ); // A1 that is the statement identifier 
A2: printf ( "the Hello world"); 
	GOTO A2; // GOTO form an infinite loop 
	getchar ();
} 


// if the complex is formed GOTO loop 
void main3 () {

	. 1 I = int; 
A1: IF (I <10) {// cycle conditions 
	printf ( "\ n% d" , i); // A1 that is the identifier of the statement 
	I ++; 
	GOTO A1; // loop formed GOTO 
} 
   getchar (); 
} 

/// goto implemented with three loop 
void main4 () { 
	// output 1-10 is not divisible by the number 3 
	for (int. 1 = I; I <= 10; I ++) { 
		IF (% I == 0. 3) { 
			Continue; 
		} 
		the printf ( "% D \ n-", I); 
	} 
	// goto rewritten with 
	int J = 0; 
A1: IF (J <10) { 
		J ++; 
		IF (J ==. 3% 0) { 
		
			GOTO A1; 
		} 
		the printf ( "% D \ n-", J); 
		GOTO A1; 
	} 
	getchar (); 
} 

void main () { 
	// first output 1-10 divisible by 3 
	for (int I =. 1; I <= 10; I ++) {
		if (i % 3 == 0){
			printf("%d\n", i);
			break;
		}
	}
	//用goto改写
	int j = 0;
A1:if (j <10){
	j++;
	if (j % 3 == 0){
		printf("%d\n", j);
		goto A2;
	}
	goto A1;
}
  A2:getchar();
}

 

Guess you like

Origin www.cnblogs.com/luoxuw/p/11257788.html