Showing posts with label loops. Show all posts
Showing posts with label loops. Show all posts

Saturday, January 5, 2013

C++11 new feature Range based loop

//new c++11 standard feature

#include <iostream>
#include <vector>
using namespace std;

int main()
{
    int ia[] = {1,2,3,4,5,6,7,8,9,10};


    vector<int> iv(ia, ia + (sizeof(ia) / sizeof(int)));
   
    for ( int i:ia )

    {
        cout << i << " ";
    }
    cout << endl;
   
    for(int i:iv){
        cout << i << " ";
    }
    cout << endl;
   
    return 0;
}


OUTPUT:



Wednesday, June 20, 2012

Program to understand Do While loop

//The body of the loop will be executed at least once before the condition is checked
#include<iostream>
#include<string>
using namespace std;

int main()
{
    string password;
   
    do
    {
        cout << "Enter your password: ";
        cin >> password;
    }
   
    while (password != "foobar");         //notice semicolon
    cout << "welcome, you enterted right password";
}



Thursday, February 23, 2012

using a for loop to print Ten Non-Negative Numbers

#include <iostream>
using namespace std;

int main()
{
    for (int i=0; i!=10; i=i+1)
    cout << "\n" << i;
}


OUTOUT: