C++教程
C++控制语句
C++函数
C++数组
C++指针
C++对象
C++继承
C++多态
C++抽象
C++常用
C++ STL教程
C++迭代器
C++程序

C++ Goto语句

C++ goto语句也称为跳转语句。它用于将控制权转移到程序的其他部分。
它可以无条件地跳转到指定的标签。
它可以用于从深层嵌套的循环或切换案例标签转移控制。

C++ Goto语句示例

让我们看一下C++中goto语句的简单示例。
#include <iostream>
using namespace std;
int main()
{
ineligible:  
         cout<<"You are not eligible to vote!\n";  
      cout<<"Enter your age:\n";  
      int age;
      cin>>age;
      if (age < 18){  
              goto ineligible;  
      }  
      else  
      {  
              cout<<"You are eligible to vote!";   
      }       
}
输出:
You are not eligible to vote!
Enter your age:
16
You are not eligible to vote!
Enter your age:
7
You are not eligible to vote!
Enter your age:
22
You are eligible to vote!
昵称: 邮箱:
Copyright © 2022 立地货 All Rights Reserved.
备案号:京ICP备14037608号-4