代码执行顺序 continue、break、goto、return。

正常计算机代码的执行顺序是从上至下,除非有逻辑语句跳转。

以前没了解goto的使用,现在研究一下goto还是挺有意思的。

下面是c++简单的代码demo。

void Main::xecutionTest()
{
     for (int i = 0; i<10; i++)
     {
          switch (getCode())
          {
              case 0:
                   cout << "Ignore this item";
                   continue;
              case 1:
              mCase:
                   cout << "End the whole cycle";
                   break;
              case 2:
                   cout << "Jump to the specified position";
                   goto mCase;
              case 3:
                   cout << "End this function";
                   return;
              default:
                   cout <<"Invalid selection";
                   break;
           }
     }
     cout << "Normal execution";
}

 

下面是c#简单的代码(c++也适用c#)demo。

       

         void xecutionTest()
        {
            for (int i = 0; i < 10; i++)
            {
                switch (getCode())
                {
                    case 0:
                        Console.WriteLine("Ignore this item");
                        continue;
                    case 1:
                        Console.WriteLine("End the whole cycle");
                        break;
                    case 2:
                        Console.WriteLine("Jump to the specified position");
                        goto case 1;
                    case 3:
                        Console.WriteLine("End this function");
                        return;
                    default:
                        Console.WriteLine("Invalid selection");
                        break;
                }
            }
            Console.WriteLine("Normal execution");
        }


  下面是java简单的代码demo 。

 public static void main(String[] args) {
      for (int i = 0; i<10; i++)
      {
           switch (getCode())
           {
               case 0:
                System.out.println("Ignore this item");
                    continue;
               case 1:
               mCase:
                System.out.println("End the whole cycle");
                    break;
               case 2:
                System.out.println("Jump to the specified position");
                break mCase;
               case 3:
                System.out.println("End this function");
                    return;
               default:
                System.out.println("Invalid selection");
                    break;
            }
      }
      System.out.println("Normal execution");
 }

 

下面是php简单的代码demo 。

function xecutionTest(){

 for (int i = 0; i<10; i++)
 {
     switch (getCode())
     {
         case 0:
            echo "Ignore this item";
            continue;
         case 1:
            mCase:
            echo "End the whole cycle";
            break;
         case 2:
            echo "Jump to the specified position";
            goto mCase;
         case 3:
            echo "End this function";
            return;
         default:
            echo "Invalid selection";
            break;
         }
     }
     echo "Normal execution";
 }
}









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

bug狂人

让我们和小姐姐唠嗑可以肢愣起来

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值