2026-09-14
do_continue.c
#include <stdio.h>
int main(void) {
int i = 0;
do {
i++;
if (i < 3) continue;
printf("%d\n", i);
} while (0);
printf("end %d\n", i);
}
これは何を出力するでしょうか?
Answer
end 1(その後に改行)のみ。continueは「ループの先頭へ戻る」文ではなく「ループ本体の末尾へ飛ぶ」文で、do〜whileでは本体の末尾の次に条件式が評価されます。1周目のcontinueでwhile (0)の判定へ進み、偽なのでそのままループを抜けます。do { ... } while (0)の中のcontinueは、実質breakと同じです。