Skip to content

Instantly share code, notes, and snippets.

@paley777
Created June 18, 2022 08:20
Show Gist options
  • Save paley777/343d7aa4d03bf5cef7a750783669f6d3 to your computer and use it in GitHub Desktop.
Save paley777/343d7aa4d03bf5cef7a750783669f6d3 to your computer and use it in GitHub Desktop.
Looping C++
#include <iostream>
using namespace std;
int main()
{
int angka = 0;
// perulangan for
cout << "Perulangan menggunakan for: " << endl;
for (int i = 0; i <= 10; ++i)
{
cout << "Ini urutan ke " << i << endl;
}
cout << endl;
// perulangan while
cout << "Perulangan menggunakan while: " << endl;
while (true)
{
cout << "Ini urutan ke " << angka << endl;
if (angka==10)
{
break;
}
++angka;
}
angka = 0;
cout << endl;
// perulangan do while
cout << "Perulangan menggunakan do-while: " << endl;
do
{
cout << "Ini urutan ke " << angka << endl;
if (angka==10)
{
break;
}
++angka;
}
while (true);
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment