第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

為了賬號安全,請及時綁定郵箱和手機(jī)立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

if 語句和后增量作業(yè):我沒有得到我期望的結(jié)果 - 為什么?

if 語句和后增量作業(yè):我沒有得到我期望的結(jié)果 - 為什么?

C#
FFIVE 2023-08-20 14:37:39
抱歉,如果這是一個愚蠢的初學(xué)者問題,但我完全被難住了。int i = 0;if (i == 0)    i++;    i++;if (i == 3)    i += 2;    i += 2;Console.WriteLine(i);好的,我的邏輯是,如果i = 0,添加1,然后添加1到該內(nèi)容。所以最后i = 2。除非不是,否則它會打印出來4。唯一可能發(fā)生的情況是它通過了第二個“if 語句”。正確的?我缺少什么?
查看完整描述

2 回答

?
繁星點(diǎn)點(diǎn)滴滴

TA貢獻(xiàn)1803條經(jīng)驗 獲得超3個贊

是的,是的4,讓我們格式化代碼(右縮進(jìn))并查看:


int i = 0;   // i == 0


if (i == 0)  // i == 0

    i++;     // i == 1


i++;         // i == 2


if (i == 3)  // i == 2

    i += 2;  // doesn't enter (since i != 3)


i += 2;      // i == 4



查看完整回答
反對 回復(fù) 2023-08-20
?
HUWWW

TA貢獻(xiàn)1874條經(jīng)驗 獲得超12個贊

您需要使用大括號 { } 來表示超出單行條件的任何內(nèi)容,或者僅在條件為 true 時執(zhí)行后的第一行代碼。


/*

for example would be?


if (i == 0)?

{

? ? i++;?

? ? i++;?

}

*/


int i = 0;


//this is true

if (i == 0)

? ? i++; // so only this line gets executed i = 1

? ? i++; // this will get executed no matter what. i = 2

//at this point i = 2 so the conditional is false

if (i == 3)

? ? i += 2; // this line doesn't get executed

? ? i += 2; /* this is not in curly brackets { } so it will get executed no matter what the conditional returns as .. so i = 4*/


//i = 4

Console.WriteLine(i);

//and that's what prints

查看完整回答
反對 回復(fù) 2023-08-20
  • 2 回答
  • 0 關(guān)注
  • 126 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動學(xué)習(xí)伙伴

公眾號

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號