NESTED LOOP


 

Apaitu Nested Loop ?

Nested Loop adalah perulangan di dalam perulangan sehingga membentuk banyak perulangan yang harus di proses.

Contoh Nested Loop
    - Nested Loop For
Notasi
judul
    membuat deret angka dengan nested for 
kamus
    a,b : integer
    c,d : integer
deskripsi
    input a
    input b
    for (c=1; c<=a; c++)
    {
        for (d=1; d<=b; d++)
        {
               output d
        }
        output  endl
    }
    output

Coding
#include <iostream>

using namespace std;
int a,b;
int c,d;

int main ()
{
    cout << "Masukkan batas baris (deret turun) : \n";
    cin >> a;
    cout << "Masukkan batas kolom (deret kesamping) : \n";
    cin >> b;
    cout << endl;

    for (c=1; c<=a; c++)
    {
        for (d=1; d<=b; d++)
        {
               cout << d << " ";
        }
    cout << endl;
    }
    return 0;
}

Hasil Run

    - Nested Loop While
Notasi
judul
    membuat deret angka dengan nested while 
kamus
    a,b : integer
    c,d : integer
deskripsi
    input a
    input b
    c=1
    while (c<=a)
    {   d=1
        while (d<=b)
        {
               output  d , " "
               d++
        }c++
    output endl
    }
    output

Coding
#include <iostream>

using namespace std;
int a,b;
int c,d;

int main ()
{
    cout << "Masukkan batas baris (deret turun) : \n";
    cin >> a;
    cout << "Masukkan batas kolom (deret kesamping) : \n";
    cin >> b;
    cout << endl;

    c=1;
    while (c<=a)
    {   d=1;
        while (d<=b)
        {
               cout << d << " ";
               d++;
        }c++;
    cout << endl;
    }
    return 0;
}

Hasil Run


    - Nested Loop Do - While
Notasi
judul
    membuat deret angka dengan nested do-while 
kamus
    a,b : integer
    c,d : integer
deskripsi
    input a
    input b
    c=1
    do {
        d=1
        do {
               output d , " "
               d++
        } while (d<=b)

        c++
    output  endl
    } while (c<=a)
    output

Coding
#include <iostream>

using namespace std;
int a,b;
int c,d;

int main ()
{
    cout << "Masukkan batas baris (deret turun) : \n";
    cin >> a;
    cout << "Masukkan batas kolom (deret kesamping) : \n";
    cin >> b;
    cout << endl;

    c=1;
    do {
        d=1;
        do {
               cout << d << " ";
               d++;
        } while (d<=b);

        c++;
    cout << endl;
    } while (c<=a);

    return 0;
}

Hasil Run


Komentar

Postingan populer dari blog ini

NESTED CONDITION