不用真假判斷,也可以嗎?hasNopass在整個(gè)程序中有什么重要作用?
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? int[] score = { 85,76,98,100,62,60};//分?jǐn)?shù)
? ? ? ? ? ? bool hasNopass = false;//記錄是否有不及格的,默認(rèn)沒有
? ? ? ? ? ? for (int i = 0; i < score.Length; i++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if (score[i] < 60)//如果有不及格的
? ? ? ? ? ? ? ? {
? ? ? ? ? ? ? ? ? ? //hasNopass=true;
? ? ? ? ? ? ? ? ? ? Console.WriteLine("有人不及格");
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? ? ??
? ? ? ? ? ? ? ? }
? ? ? ? ? ? ? ? else{
? ? ? ? ? ? ? ? ? ? Console.WriteLine("都及格啦!");
? ? ? ? ? ? ? ? ? ? break;
? ? ? ? ? ? ? ? }
? ? ? ? ? ? }
? ? ? ? ? ? /*//if (hasNopass)
? ? ? ? ? ? ? ?// Console.WriteLine("有人不及格"http://);
? ? ? ? ? ? //else
? ? ? ? ? ? ? //? Console.WriteLine("都及格啦!"http://);
*/
? ? ? ? }
? ? }
}
2020-07-23
樓上說的對(duì),所以break是不能亂用的
2019-03-20
你這樣,第一個(gè)數(shù)85進(jìn)來,就進(jìn)入else里面,然后輸出都及格了,不管數(shù)組后面的數(shù)是多少都不再進(jìn)行判斷了,因?yàn)槟阋呀?jīng)break跳出了。