有大佬幫我看看嗎
我這段代碼,已經(jīng)加了%2不為0的條件,為什么結(jié)果還是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 ;? ?//添加關(guān)鍵字break或continue
? ? ? ? ? ? ? ? Console.Write(x);
? ? ? ? ? ? }
? ? ? ? }
? ? }
}
2020-09-15
if判斷里面的&&是并且的意思,只有兩邊都為true的時(shí)候才會(huì)走break語句,然而x>5這個(gè)條件一直是false,所以就會(huì)輸出12345