#include <iostream>
#include <algorithm>

#define Repeat do{
#define Until(cond) }while(!(cond))

void printer(int i)
{
    std::cout<<i<<" ";
}

int main()
{
    int i = 0;
    
    //Simulating Pascal/Delphi's repeat until loop.
    //This loop will run once and then check the condition.
    //After that, it will continue again if the condition is true.
    Repeat
        std::cout<<i<<" ";
        ++i;
    Until(i == 10);

    i = 0;
    std::cout<<"\n";

    //will only run while this condition is true.. i must be less than 10 for the loop to start and continue.
    //in other words, the loop will only start and continue if the condition is true.
    while (i < 10)
    {
        std::cout<<i<<" ";
        ++i;
    }

    std::cout<<"\n";
    i = 0;

    //will run at least once. The condition is checked after the first run.
    //If it is true, the loop will run again and continue running while the condition is true.
    do
    {
        std::cout<<i<<" ";
        ++i;
    } while(i < 10);

    std::cout<<"\n";
    i = 0;

    //sets the initial value of J to 0.
    //While (J < 10) the loop will run.
    //At the end of each iteration, J is incremented.
    for (int j = 0; j < 10; ++j)
    {
        std::cout<<j<<" ";
    }

    std::cout<<"\n";



	//You must be using a C++11 compiler to use any of the following loops!!
	
    int arr[] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};

	//for each integer in arr, call lambda function and pass that integer as an argument.
	//in this case, the function is [](int i) {  std::cout<<i<<" ";  }
    std::for_each(&arr[0], &arr[10], [](int i) {std::cout<<i<<" ";});
    std::cout<<"\n";


    //same as above.. for each integer in arr, call the printer function and pass that integer
    //as an argument. Thus every loop it does:  printer(i); where i is an integer in arr array.
    std::for_each(&arr[0], &arr[10], printer);
    std::cout<<"\n";

	//for-ranged loop.
	//for each integer in arr, copy the value to variable i and print it.
    for(int i : arr)
    {
        std::cout<<i<<" ";
    }

    std::cout<<"\n";


	//for each integer in arr, do NOT copy the value. Instead, reference it and print it.
	//this allows you to be able to change the value of i and it'd change the value in the array.
    for (int &i : arr)
    {
        std::cout<<i<<" ";
    }

    std::cout<<"\n";
    
    
    //for each "something" in "some array", copy it to variable i and print it.
    for (auto i : arr)
    {
    	std::cout<<i<<" ";
    }
    
    std::cout<<"\n";
    

    //for each "something" in "some array", do NOT copy it. Reference it and print it.
    for (auto &i : arr)
    {
        std::cout<<i<<" ";
    }
}
