gpt4 book ai didi

c# - 如何结束循环

转载 作者:太空宇宙 更新时间:2023-11-03 17:08:55 26 4
gpt4 key购买 nike

开始学习循环。这些事情似乎永远持续下去,因为我没有告诉它停止。问题是我不知道如何让它停止。我假设一个语句,例如 != 但我真的不知道。

有人愿意解释循环是如何停止的吗?

 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);
}
}
}
}

最佳答案

break语句将“跳出”循环。

或者,您可以将 bool 值 (triLoop) 设置为 false

关于c# - 如何结束循环,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/18340713/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com