Program C++ Looping

Contoh While

#include <stdio.h>
#include <conio.h>
#include <iostream.h>

main()
{
int bil=1;
while(bil<=5) {
cout<< bil;
bil++; }
getch();
}

Contoh While Menampiklan Angka 10 sampai dengan 1

#include <stdio.h>
#include <conio.h>
#include <iostream.h>

main()
{ int i;
i=10;
while (i>0)
{
cout <<i<<endl;
i–;
}
getch();
}

Contoh Do While Menampiklan AMIK BSI Purwokerto dengan 1

#include <stdio.h>
#include <conio.h>
#include <iostream.h>

main()
{
int a = 1;

// do loop execution
do {
cout << "value of a: " << a << endl;
a = a + 1;
} while( a <= 20 );

getch();
}

Contoh FOR Continue dan Break

#include <stdio.h>
#include <conio.h>
#include <iostream.h>

main()
{
int i;
for(i=0;i<=15;i++)
{
cout <<i<<endl;
}
getch();
}

Contoh FOR

#include <stdio.h>
#include <conio.h>
#include <iostream.h>

main()
{
int i;
for(i=0;i<=15;i++)
{
if(i==4)continue;
cout <<i<<endl;
if(i==6)break;
}

Leave a Reply