Syntax for do... while... looping on C programming language is:
do
{
statement_yang_akan_diulang;
}
while (syarat_perulangan);
Example of do... while... on C programming language:
main()
{
int a=0;
do
{
printf("Test\n");
a=a+1;
}
while (a<2);
getch();
}
If looping condition is changed from a<2 becomes a<=2, so that program syntax becomes:
main()
{
int a=0;
do
{
printf("Test\n");
a=a+1;
}
while (a<=2);
getch();
}
Can be used looping conditional large than (>):
main()
{
int a=1000;
do
{
printf("Tes\n");
a=a-1;
}
while (a>=998);
getch();
}
Thank you... : )
do
{
statement_yang_akan_diulang;
}
while (syarat_perulangan);
Example of do... while... on C programming language:
main()
{
int a=0;
do
{
printf("Test\n");
a=a+1;
}
while (a<2);
getch();
}
- First, a valued 0, 0<2, printed word Tes and add valued of a becomes 1 (a=a+1, a=0+1, a=1) saat a<2
- Now, a valued 1, 1<2, printed word Tes and add valued of a becomes 2 (a=a+1, a=1+1, a=2) saat a<2
- Now, a valued 2, 2 is not < 2, not printed word Tes and add valued of a becomes 3 (a=a+1, a=1+1, a=2)
If looping condition is changed from a<2 becomes a<=2, so that program syntax becomes:
main()
{
int a=0;
do
{
printf("Test\n");
a=a+1;
}
while (a<=2);
getch();
}
- First, a valued 0, 0<=2, printed word Tes and add valued of a becomes 1 (a=a+1, a=0+1, a=1) saat a<=2
- Now, a valued 1, 1<=2, printed word Tes and add valued of a becomes 2 (a=a+1, a=1+1, a=2) saat a<=2
- Now, a valued 2, 2<=2, printed word Tes and add valued of a becomes 3 (a=a+1, a=2+1, a=3) saat a<=2
- Now, a valued 3, 2 is not < 2, not printed word Tes and add valued of a becomes 4 (a=a+1, a=3+1, a=4)
Can be used looping conditional large than (>):
main()
{
int a=1000;
do
{
printf("Tes\n");
a=a-1;
}
while (a>=998);
getch();
}
Thank you... : )
0 komentar:
Posting Komentar