while(1)和for(;;)語法表達
while( 表達式 ){ 語句}
for(表達式1; 表達式2; 表達式3) { 語句}1.先求解表達式1 2.求解表達式2 若其值為真(非0),則執行for語句中指定的內嵌語句,然后執行下面第3)步; 若其值為假(0),則結束循環,轉到第5)步。 3.求解表達式3 4.轉回上面第2)步繼續執行。 5.循環結束,執行for語句下面的一個語句。

while(1)和for(;;)異同點
驗證while(1)和for(;;)差異
int main(int argc, char const *argv[]){while(1){}return 0;}
int main(int argc, char const *argv[]){for(;;){}return 0;}
gcc -S -o while.s while.cgcc -S -o for.s for.c; filename: whiles .file "while.c" .text .globl main .type main, @functionmain:.LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl %edi, -4(%rbp) movq %rsi, -16(%rbp).L2: jmp .L2 .cfi_endproc.LFE0: .size main, .-main .ident "GCC: (GNU) 9.3.0" .section .note.GNU-stack,"",@progbits; filename: for.s .file "for.c" .text .globl main .type main, @functionmain:.LFB0: .cfi_startproc pushq %rbp .cfi_def_cfa_offset 16 .cfi_offset 6, -16 movq %rsp, %rbp .cfi_def_cfa_register 6 movl %edi, -4(%rbp) movq %rsi, -16(%rbp).L2: jmp .L2 .cfi_endproc.LFE0: .size main, .-main .ident "GCC: (GNU) 9.3.0" .section .note.GNU-stack,"",@progbits