Nested loop conditions

Hi,

is there any way in C++ to make conditions inside a nested for loop?

I have a nested loop and I have an if condition. If the if condition is not true then I want the loop to break and the next inner loop (j) to start from 1 not 0.

The reason I want to do this is because I'm saving values inside the 2d array. If I only used " Break ", the value of the current "i,j" will be lost. So I want the program to save it into the next i and j=0 and then start the next loop from j=1.

Please note that the order of the array is important. As I'm trying to the values of cities into an array. that's why I didn't save the values into a temp array.


1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
    for (int i=0;i<12;++i) {
                    a = i+1;
    for (int j=0;j<31;++j){

       getline(inFile,x[j][i],'/');
       getline(inFile,x2[j][i],'/');   
       getline(inFile,x3[j][i],'/');      
       getline(inFile,x4[j][i],'\:');      
       stringstream convertor(x2[j][i]);
       convertor >> d2[j][i];
       if (d2[j][i] == a){
       }else {

           x[0][i+1] = x[j][i];  
             break;
       }
       }
    }
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int begin = 0;
for (int i = 0; i < 12; ++i) {
	a = i + 1;
	int j = begin;
	begin = 0; //if you want to reset for the next one
	for (/*nothing here*/; j < 31; ++j) {
		//...
		if (d2[j][i] == a) {
		} else {
			x[0][i + 1] = x[j][i];
			begin = 1; //<---
			break;
		}
	}
}
¿can you explain your file structure?
be careful with out of bound accesss.

also, '\:', don't think you should escape that.
im dividing 4 numbers which identifies the cities. I'm not having a problem with reading the file.

So, I'm saving the values of them into 4 different arrays (x,x2,x3,x4) and at the end I'm working on them. The order of them is important for me because I can track them based on the array dimensions.

My problem is the for loop.

Last one, it was a typo when I added the code. it's only " \".

Ex. 20/459/548421/23NY \
@ne555: Just tried it out!

It worked and I have to say thanks a million sir!

Wish you had a nice weekend thou.
Topic archived. No new replies allowed.