Lecture-5.6 [All Loop]

ForLoop


1. ForLoop.cpp


#include <iostream>

using namespace std;
int main()
{
    for (int i = 0; i <= 100; i++)
    {
        cout << i;
        cout << " ";
        printf("I Love My Dreams\n");
    }

    return 0;
}


2. ForLoop2.cpp


#include <iostream>

using namespace std;

int main()
{
    int a, b;
    printf("How Much you want the number\n");
    cin >> a;
    printf("Which Number you want maltiplay\n");
    cin >> b;
    for (int i = 1; i <= a; i++)

        if ((i % b) == 0)
        {
            cout << " =  " << i << "\n";
        }

    return 0;
}



While Loop


1. WhileLoop.cpp


/*in the programing
    1 = true
    0 = false */

#include <iostream>
using namespace std;
int main()
{

    while (1)
    {
        printf("Helle Brother\n");
    }

    return 0;
}


2. WhileLoop_2.cpp

#include <iostream>
using namespace std;
int main()
{

    int a = 0;
    while (a < 10)
    {
        printf("Vikash\n");
        a++;
        //a++ increasing value 1 by 1 of a
    }

    return 0;
}


3. WhileLoop_3.cpp


#include <iostream>
using namespace std;

int main()
{
    int a;
   
    cin >> a;

    while (a > 5 && a < 10)
    {
        printf("Hello\n");
        a++;
    }
}


4. WhileLoop_4.cpp

#include <iostream>
using namespace std;
int main()
{
    int a;
    printf("Enter Your Number For  Loop\n");
    cin >> a;
    while (a < 10 || a > 5)             // in this program || = OR when we are using this it chack both any if it get any true it run the program
    {
        printf("Hello\n");
        a++;
    }
}


Continue Loop


1. Continue.cpp

#include <iostream>
using namespace std;
int main()
{

    for (int i = 0; i < 10; i++)
    {
        if (i == 5)
            continue;
        cout << i;
        printf("\n");
    }

    return 0;
}


Brack Loop


1. BrackLoop.cpp


#include <iostream>
using namespace std;

int main()
{
    for (int i = 0; i < 10; i++)
    {
        if (i == 5)
            break;
        cout << i << endl;
    }
    return 0;
}

Give Same Suggestion