c# while-do while-foreach-if-goto

using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;//arraylist派生于array类

namespace ConsoleApplication1
{
    class Program
    {
       //学习while
      public static void Main(string[] args)
      {
          int[] x=new int[3] {1,5,7};

          foreach (int i in x)
          {
              Console.WriteLine(i);
          }
          Console.ReadKey();


          //学习while,
          //while语法 while(条件) {代码块;代码块中一个更新while条件的代码}
          int z = 0;
          while (z < 3)
          {
              Console.WriteLine(x[z]);
              z++;
          }
          Console.WriteLine("while测试结束");
          Console.ReadKey();

          //测试do while,至少执行一次代码块
          //do while流程:1,先执行一次do代码块,然后判断while条件判断式,如为true,继续执行do代码块,直至while为false,不再执行do代码块,退出循环
          bool exe1=false;//用于do while的条件判断式
          do
          {
              for (int i = 0; i < x.Length; i++)
              {
                  Console.WriteLine(x[i]);
              }

          } while (exe1); //如exe1为true,继续执行do中的代码块输出数组a的每个元素,因为exe1初始化false,故不再重复执行do代码块 do while的while后面有个分号
          Console.WriteLine("do while测试结束");
          Console.ReadKey();


          //学习goto跳传语句
          Console.WriteLine("请输入要查找的文字");
          string inputstr = Console.ReadLine();
          string[] mystr = new string[3];
          mystr[0] = "翟勋杨";
          mystr[1] = "翟勋涛";
          mystr[2] = "翟勋钊";
          //在mystr数组中与输入字符是否匹配,然后进行相应的处理
          for (int i = 0; i < mystr.Length;i++ )
          {
              //如果mystr数组某个元素与输入字符匹配
              if (mystr[i].Equals(inputstr))
              {
                  //用goto跳到到goto代码块
                  goto found;
              }

          }

          //说明找不到,也进行相应处理
          Console.WriteLine("什么也查找不到,匹配不了");
          goto finish;

          //找到匹配的found代码块
          found:
          Console.WriteLine("匹配的字符串是:"+inputstr);

         
          //经测试finish跳传代码块每次都会执行
          finish:
             Console.WriteLine("查找完了");
             Console.ReadLine();
      }
    }
   
}

请使用浏览器的分享功能分享到微信等