Lập trình C - Lệnh go
Lệnh go trong ngôn ngữ C
Trong ngôn ngữ C để nhảy (jump) đến nhãn được định nghĩa trước chúng ta dùng lệnh go
Cú pháp:
goto label;
Ví dụ dùng lệnh go:
#include <stdio.h>
int main() {
int age;
ineligible:
printf("You are not eligible to vote!\n");
printf("Enter you age:\n");
scanf("%d", &age);
if(age<18)
goto ineligible;
else
printf("You are eligible to vote!\n");
return 0;
}
Kết quả:
You are not eligible to vote!
Enter you age:
11
You are not eligible to vote!
Enter you age:
44
You are eligible to vote!