2 Replies - 1010 Views - Last Post: 15 February 2013 - 08:33 PM Rate Topic: -----

#1 farzanakhawja  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 7
  • Joined: 13-February 13

question regarding why we use for loop in the below codes

Posted 15 February 2013 - 07:41 PM

hi every body. I have question regarding the tracing of these codes and also why we used the for loop.
#include <iostream>  
#include <vector> //include the vector library  
   
 using namespace std;  
 int main()  
 {  
    vector<int>myVector;  

   myVector.push_back(2);  
     myVector.push_back(7);  

     myVector.push_back(7);     //vector<int>mybector;     

    for(int i=0; i<myVector.size(); i++) // to use the size member function. use myVector.size()  

   {  
        cout << myVector[i];  

    } 

 }


This post has been edited by baavgai: 16 February 2013 - 03:56 AM
Reason for edit:: tagged


Is This A Good Question/Topic? 0
  • +

Replies To: question regarding why we use for loop in the below codes

#2 sepp2k  Icon User is online

  • D.I.C Lover
  • member icon

Reputation: 2013
  • View blog
  • Posts: 3,038
  • Joined: 21-June 11

Re: question regarding why we use for loop in the below codes

Posted 15 February 2013 - 07:49 PM

That's C++, not Ruby. You're using the for loop to iterate through the vector.

This post has been edited by sepp2k: 15 February 2013 - 07:50 PM

Was This Post Helpful? 0
  • +
  • -

#3 Lemur  Icon User is offline

  • Pragmatism over Dogma
  • member icon



Reputation: 1335
  • View blog
  • Posts: 3,398
  • Joined: 28-November 09

Re: question regarding why we use for loop in the below codes

Posted 15 February 2013 - 08:33 PM

Moving to C/C++
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1