Breaking out of the loop

 
for ( int i = 0; i < 96; i++ ){ //Loop1
if ( ( TimeHour( Time[i] ) == intValue ) && ( TimeMinute( Time[i] ) == 0 ) ) {
for ( int j = i + 1 ; j < 576; j++ ){ //Loop2
if ( TimeHour( Time[j] ) == intValue ) {
count += 1;
if ( count == 5 ) {
break;
}
}
}
}
}

the break statement exits loop2 or both loops.

well i need to break both loops.

 

Before posting please read some of the other threads . . . then you would have seen numerous requests like this one:

Please use this to post code . . . it makes it easier to read.

 
faizy999:

the break statement exits loop2 or both loops.

well i need to break both loops.

Just loop2 I think . . . just add a . . .

if ( count == 5 ) break;

inside loop1 but after the code where you increment count

 
for ( int i = 0; i < 96; i++ ){
	if ( ( TimeHour( Time[i] ) == intValue ) && ( TimeMinute( Time[i] ) == 0 ) ) {
        	for ( int j = i + 1 ; j < 576; j++ ){
               		if ( TimeHour( Time[j] ) == intValue ) {
	                  Count += 1;
        	          if ( Count == 5 ) {
                	     break; //Break1
                  	  }
                	}
         	}
        }   
}
Once the execution of first if statement there no need to loop further. what i understand is that it breaks statement exits both loop or not. so i can think about the work around of that scenario. and thanks for pointing out SRC block.
 
faizy999:
Once the execution of first if statement there no need to loop further. what i understand is that it breaks statement exits both loop or not. so i can think about the work around of that scenario. and thanks for pointing out SRC block.

Yep, I think i understood what you meant . . . . this is what I meant

for ( int i = 0; i < 96; i++ )
   {
   if ( ( TimeHour( Time[i] ) == intValue ) && ( TimeMinute( Time[i] ) == 0 ) ) 
      {
      for ( int j = i + 1 ; j < 576; j++ )
         {
         if ( TimeHour( Time[j] ) == intValue ) 
            {
            Count += 1;
            if ( Count == 5 ) break; // Break out of j loop
            }
         }
      }   
      if ( Count == 5 ) break;  // Break out of i loop
   }   
 
hmm so i have to use two break statements thanks. for helping me out.
 
Or avoid the problem completely since the loops are independent.
for ( int i = 0; i < 96; i++ )
   if ( TimeHour( Time[i] ) == intValue && TimeMinute( Time[i] ) == 0 )
      break;
for ( int j = i + 1 ; j < 576; j++ )
   if ( TimeHour( Time[j] ) == intValue ){
       Count += 1;
       if ( Count == 5 ) break; // Break out of j loop
   }
}
Reason: