Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // While Loop
- #include <stdio.h>
- int main() {
- int i = 0;
- while (i != 0) {
- printf("%d\n", i);
- }
- return 0;
- }
- // Do-While Loop
- #include <stdio.h>
- int main() {
- int i = 0;
- do {
- printf("%d\n", i);
- } while (i != 0);
- return 0;
- }
- // For Loop
- #include <stdio.h>
- int main() {
- int i;
- for (i = 0; i < 5; i++) {
- printf("%d\n", i);
- }
- return 0;
- }
- // Contoh Continue
- #include <stdio.h>
- int main() {
- int i;
- for (i = 0; i < 5; i++) {
- if( i == 2 || i == 3) {
- continue;
- }
- printf("%d\n", i);
- }
- return 0;
- }
- //Nested Loop
- #include <stdio.h>
- int main() {
- int tinggi;
- printf("Masukkan tinggi segitiga: ");
- scanf("%d", &tinggi);
- for (int i = 0; i < tinggi; i++) {
- for (int j = 0; j <= i; j++) {
- printf("* ");
- }
- printf("\n");
- }
- return 0;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement