测试goto语句
示例1:
#includeint main(){ int choice = 4; if (choice==1){ printf("choice1:%dn",choice); goto error1; } else if (choice==2) { printf("choice2:%dn",choice); goto error2; } error2: { printf("choice error2:%dn",choice); printf("This is error2n",choice); } error1: printf("choice error1:%dn",choice); printf("This is error1n",choice); printf("test outputn"); return 0; }
示例2:
#includeint main(){ int choice = 1; if (choice==1){ printf("choice1:%dn",choice); goto error1; } else if (choice==2) { printf("choice2:%dn",choice); goto error2; } error2: { printf("choice error2:%dn",choice); printf("This is error2n",choice); } error1: printf("choice error1:%dn",choice); printf("This is error1n",choice); printf("test outputn"); return 0; }
示例3
#includeint main(){ int choice = 2; if (choice==1){ printf("choice1:%dn",choice); goto error1; } else if (choice==2) { printf("choice2:%dn",choice); goto error2; } error2: { printf("choice error2:%dn",choice); printf("This is error2n",choice); } error1: printf("choice error1:%dn",choice); printf("This is error1n",choice); printf("test outputn"); return 0; }



