Home > Backend Development > C#.Net Tutorial > Usage of goto statement in c language

Usage of goto statement in c language

angryTom
Release: 2020-03-09 17:28:22
Original
9107 people have browsed it

Usage of goto statement in c language

Usage of goto statement in c language

The goto statement can make the program jump to the specified location without any conditions, so goto Statement is also called an unconditional jump statement.

Recommended learning: Introduction to Programming Tutorial

Its syntax is as follows

goto label;
//其它代码
label:
Copy after login

Among them, label is a label defined by ourselves, and the defined rules are the same as The variable has the same name, and its position is not fixed. It can be written after the goto statement or in front of it. However, the goto statement can only jump within a function, and it does not allow jumping out of a function. outside the function.

int day = 1;
loop:
if (day <= 31){
    printf("%d\n", day);
    day++;
    goto loop;
}
Copy after login

The above program uses goto and if statements to implement the loop function. It is the same as the loop function implemented by while, where loop is a label defined by us.

Usage of goto statement in c language

Note: Avoid using goto statements, which will disrupt the program structure and make it difficult to read.

Recommended learning: c language video tutorial

The above is the detailed content of Usage of goto statement in c language. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template