for … else …
請按下方▷,看看和你想得一不一樣
你 484 以為只會印五行,那你該讀文件了
(Yes, this is the correct code. Look closely: the else clause belongs to the for loop, not the if statement.)
When used with a loop, the else clause has more in common with the else clause of a try statement than it does with that of if statements: a try statement’s else clause runs when no exception occurs, and a loop’s else clause runs when no break occurs.
一圖以蔽之