// statements_goto.cs
// Nested search loops
using System;
public class GotoTest1
{
public static void Main()
{
int x = 200, y = 4;
int[,] myArray = new int[x,y]; // initialize the array:
for (int i = 0; i < x; i++)
for (int j = 0; j < y; j++)
myArray[i,j] = ++i; // Read input:
Console.Write("Enter the number to search for: "); // input a char
string s = Console.ReadLine();
int myNumber = Int32.Parse(s); // Search:
for (int i = 0; i < x; i++)
for (int j = 0; j < y; j++)
if (myArray[i,j] == myNumber)
goto Found; Console.WriteLine("The number {0} was not found.", myNumber);
goto Finish; Found:
Console.WriteLine("The number {0} is found.", myNumber); Finish:
Console.WriteLine("End of search.");
}
}
// Nested search loops
using System;
public class GotoTest1
{
public static void Main()
{
int x = 200, y = 4;
int[,] myArray = new int[x,y]; // initialize the array:
for (int i = 0; i < x; i++)
for (int j = 0; j < y; j++)
myArray[i,j] = ++i; // Read input:
Console.Write("Enter the number to search for: "); // input a char
string s = Console.ReadLine();
int myNumber = Int32.Parse(s); // Search:
for (int i = 0; i < x; i++)
for (int j = 0; j < y; j++)
if (myArray[i,j] == myNumber)
goto Found; Console.WriteLine("The number {0} was not found.", myNumber);
goto Finish; Found:
Console.WriteLine("The number {0} is found.", myNumber); Finish:
Console.WriteLine("End of search.");
}
}
………………goto next;
…………………………
…………………………
next; } //花括号前直接有个标