May 22, 2018 at 8:49am UTC
I am back again... :D
I am trying to figure out if it's possible to implement multiple range-based for loops?
So far, I see the patterns like:
for (Pt2 p : vertices2)
{
cout << "\nVertices2: ";
cout<< p.x<<" ";
cout << p.y<<" ";
cout << p.z<<" \n";
}
I am thinking if it's also possible to put multiple range-based for loops such as:
for (Pt2 p : vertices2) & (Pt2 q : vertices2)
{
cout << "\nVertices2: ";
cout<< p.x<<" ";
cout << p.y<<" ";
cout << p.z<<" \n";
cout << "\nVertices2: ";
cout<< q.x<<" ";
cout << q.y<<" ";
cout << q.z<<" \n";
}
My syntax is bad and not working. I would like to ask the proper way of doing it if it's possible. Thank you for your response in advance. :)
Last edited on May 22, 2018 at 8:54am UTC
May 22, 2018 at 9:20am UTC
What are you trying to do? Is it this?
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20
#include <iostream>
#include <vector>
int main()
{
std::vector<int > vertices2{1,2,3,4,5};
for (int p : vertices2)
{
for (int q : vertices2)
{
{
std::cout<< p << "-" << q << '\n' ;
}
}
std::cout << " Next p\n" ;
}
}
Last edited on May 22, 2018 at 9:23am UTC
Jun 14, 2018 at 3:09am UTC
Thank you very much Mr. Repeater for your response. I overlooked this thread.
I was trying to figure out if it's possible to read and output values in just one loop?
However, since I am not good in programming, what I did was to call them twice just to output separately the values of p and q.