วิชาการเขียนโปรแกรมด้วยภาษาซี (c)

คำสั่ง do while ภาษาซี c programming

สำหรับคำสั่ง do while จะทำงานคล้ายกับ while แต่ลักษณะการทำงาน จะทำงานตามคำสั่ง do ก่อน 1 รอบ แล้วจึงเริ่มตรวจสอบเงื่อนไขที่ while เป็นครั้งแรก หากเงื่อนไขเป็นจริงก็จะทำงานวนรอบไปเรื่อย ๆ จนกว่าเงื่อนไขจะเป็นเท็จ จึงจะออกจากลูป


ข้อควรทราบ คำสั่ง do while จะทำงานอย่างน้อย 1 ครั้งแม้ว่าจะตรวจสอบเงื่อนไขแล้วพบว่าเงื่อนไขเป็นเท็จ


ตัวอย่างคำสั่ง do while ภาษาซี (c)

#include <stdio.h> 
main() 
{
int i = 1;
do{
	printf ("%d\n",i);
	++i;
}
while (i<10);
}

ผลลัพธ์ที่ได้

1
2
3
4
5
6
7
8
9

slot gacor hari ini slot qris slot gacor maxwin slot online slot gacor gampang menang slot gacor hari ini slot online slot slot slot guci777 guci777 fafatogel fafatogel fafatogel fafatogel agen138 slot agen138 slot data hk bola slot bolaslot99 bola slot agen138 link alternatif koin138 link alternatif agen138 slot ag138 slot slot gacor slot thailand