有大佬幫我看看嗎
我這段代碼,已經加了%2不為0的條件,為什么結果還是12345
using System;
using System.Collections.Generic;
using System.Text;
namespace Test
{
? ? class Program
? ? {
? ? ? ? static void Main(string[] args)
? ? ? ? {
? ? ? ? ? ? for(int x=1;x<=5;x++)
? ? ? ? ? ? {
? ? ? ? ? ? ? ? if(x%2 != 0 && x>5)
? ? ? ? ? ? ? ? break ;? ?//添加關鍵字break或continue
? ? ? ? ? ? ? ? Console.Write(x);
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
2020-09-15
if判斷里面的&&是并且的意思,只有兩邊都為true的時候才會走break語句,然而x>5這個條件一直是false,所以就會輸出12345