如下代碼所示,為什么在循環體外面聲明y不行
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? int x = 1;
? ? ? ? ? ?/*int y = 1;
? ? ? ? ? ? 為什么在這里聲明y,打印出來就只有第一行
? ? ? ? ? ? 0......0*/
? ? ? ? ? ? ? ?for (; x <= 7; x++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? for (int y = 1;y <= 7;y++)
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? if (x == y || x + y == 8)
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Console.Write("O");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? ? ? else
? ? ? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? ? ? Console.Write(".");
? ? ? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? Console.WriteLine();
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
2020-01-07
應該是在循環體外面的x、y的值是不受循環體內影響,導致無法繼續循環下去,只輸出了一層就打印出來了
2019-11-14
不影響啊