Perulangan (While, Do - While)

You might also like

Download as docx, pdf, or txt
Download as docx, pdf, or txt
You are on page 1of 3

PERULANGAN (WHILE, DO – WHILE)

Contoh 1 (While)

/* Program Perulangan menggunakan while */

#include <iostream.h>

main()

int x;

x = 1; /* awal variabel */

while (x <= 10) /* Batas akhir perulangan */

cout<<"Bahasa C++ "<<endl;

x ++; /* variabel x ditambah dengan 1 */

return 0;

Contoh 2 (While)

#include <iostream.h>

main()

int i = 0;

while (i != 99)

cout<<" Masukkan Sebuah Bilangan : ";

cin>>i;

cout<<"Bilangan Anda adalah= "<<i<<endl;

}
Contoh 3 (Do – While)

#include <iostream.h>

main()

int x;

x = 1;

do

cout<<"BAHASA C++ "<<endl;

x ++;

while(x <= 10);

return 0;

You might also like