1. while loop
#include <iostream.h>
int main()
{
int len;
cout<<"masukan panjang (1-79): ";
cin>>len;
while(len>0&&len< 80){
cout<<len<<" ";
len--;
}
cout<<endl;
return 0;
2. DO WHILE
#include <iostream.h>
int main()
{
for(int i=0; i<=3; i++)
cout<<i<<" ";
cout<<endl;
cout<<"pake while\n";
int i=0;
while(i<=3){
cout<<i<<" ";
i++;}
cout<<endl;
cout<<"pake do while\n";
i=0;
do{
cout<<i<<" ";
i++;
}
while(i<=3);
return 0;
}
Tidak ada komentar:
Posting Komentar