如何结束循环

Zor*_*oro 1 c# loops

开始学习循环.似乎这些事情永远存在,因为我并没有告诉它停止.问题是我不知道如何告诉它停止.我假设一个声明,如!=但我真的不知道.

有人在意解释循环如何停止?

 using System;
 using System.Collections.Generic;
 using System.Linq;
 using System.Text;

 namespace ConsoleApplication326
 {
class Program
{
    static void Main(string[] args)
    {
        bool triLoop = true;
        while (triLoop)
        {
            Console.WriteLine("Please enter the first integer...");
            int firstInt = int.Parse(Console.ReadLine());
            Console.WriteLine("Please enter the second integer...");
            int secondInt = int.Parse(Console.ReadLine());
            Console.WriteLine("Please enter the third integer...");
            int thirdInt = int.Parse(Console.ReadLine());

            if ((firstInt + secondInt > thirdInt) && (secondInt + thirdInt > firstInt) && (firstInt + thirdInt > secondInt))
            {
                Console.WriteLine("The numbers {0}, {1}, and {2} CAN represent sides of the same triangle.", firstInt, secondInt, thirdInt);
            }

            else
            {
                Console.WriteLine("The numbers {0}, {1}, and {2} CANNOT represent the sides of the same triangle.", firstInt, secondInt, thirdInt);
            }
        }
    }
}
Run Code Online (Sandbox Code Playgroud)

}

Ree*_*sey 6

break声明将"突破"循环.

或者,您可以将布尔值(triLoop)设置为false.