Выход из цикла при вводе слова - C#
Формулировка задачи:
Ребята, доброе время суток! Подскажите пожалуйста, можно ли реализовать цикл, чтоб при определенном слове цикл прекращал свою работу. Вот, к примеру, код, как сделать так, чтобы при написании в значении х слова stop цикл заканчивался. Или может кто подскажет, как по-другому остановить цикл?
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace 2._2
{
class Program
{
static void Main()
{
string m = "stop";
Console.Write("x= ");
double x = double.Parse(Console.ReadLine());
Console.Write("y= ");
double y = double.Parse(Console.ReadLine());
const int r = 15;
const int R = 25;
if ((x * x + y * y < r * r) || (x * x + y * y > R * R))
{
Console.WriteLine("да");
}
else
{
if ((x * x + y * y > r * r)||(x * x + y * y < R * R))
{
Console.WriteLine("нет");
}
else
{
Console.WriteLine("на границе");
}
}
Console.WriteLine(m);
Console.ReadKey();
}
}
}Решение задачи: «Выход из цикла при вводе слова»
textual
Листинг программы
using System;
using System.Text.RegularExpressions;
public class Program
{
public static void Main()
{
Regex regex = new Regex(@"\s*([+-]?[0-9]+)\s+([+-]?[0-9]+)\s*$", RegexOptions.Compiled);
Match match;
while ((match = regex.Match(Console.ReadLine())).Success)
{
double a = Double.Parse(match.Groups[1].Value);
double b = Double.Parse(match.Groups[2].Value);
Console.WriteLine(a + b);
}
}
}