1.goto语句
使用goto跳到标签的位置,
int myInteger = 5;
goto mylabel;
myInteger++;
mylabel: Console.Write(myInteger);
程序输出为5.
2.循环的各种中断
int sum = 0;
while (true)
{
int num = Convert.ToInt32(Console.ReadLine());
if(num == 0)
{
break;
}
if(num%2 == 1)
{
continue;
}
sum += num;
}
Console.WriteLine(sum);
Console.ReadKey();
break中止循环,continue跳出当前循环,执行下一次循环。
3.枚举类型
//枚举类型的定义 枚举类型默认存储类型是整数
enum GameState
{
Pause,
Failed,
Success,
Start
}
class Program
{
static void Main(string[] args)
{
//利用定义好的枚举类型 声明变量
GameState state = GameState.Start;
Console.WriteLine(state);
Console.ReadKey();
}
}