for ( initial ; condition ; increment )
{
/* statement */
}
- initial คือ ส่วนของการตั้งค่าตัวแปล ตรงนี้จะเป็นจุดที่ทำงานอับดับแรก และทำงานเพียงครั้งเดียวก่อนเข้า for loop
- condition คือส่วนของการเช็กเงื่อนไข ถ้าเป็นถูก บล๊อกข้างล่าง for ก็จะทำงาน ถ้าผิดก็จะออกจาก for
- increment คือส่วนของการทำงานแต่ละครั้งที่ บล๊อกของ for ทำงานเสร็จสิ้นครั้งหนึ่งๆ ปกติแล้ว จุดนี้จะสัมพันธ์กับส่วนของ condition คือจะเป็นตัวเพิ่ม หรือลดค่า ของตัวแปรที่อยู่ในส่วนของ initial .
เลือกข้อที่ถูกต้องตามหลักของ syntax (สามารถตอบได้มากกว่า 1 ข้อ)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <stdio.h> | |
int main(void) | |
{ | |
int i,j; | |
setbuf(stdout,NULL); | |
// nested for loop | |
for(i = 5; i < 10; i++) | |
{ | |
printf("%d",i); | |
for(j=0 ; j < 5 && i < 8; j++) | |
{ | |
printf(" * "); | |
} | |
printf("\n"); | |
} | |
return 0; | |
} |