loop goes to infinity while getting value in subarray
I am trying to display values of array of limit 2 on every time 'previous' button click. I am storing the value in array according to user wish and displayed values of array in group of 2 but when i click previous button for displaying first 2 values in array my while loop goes to infinite. here is my code:

    -(void)previous
     {
     btnnext.enabled = TRUE;
     int j = 0;
     int k = 0;
    NSArray *subarraynormal = [[NSArray alloc]init];
    NSArray *subarraycourse = [[NSArray alloc]init];
   
    itemsRemainingnormal = tempRemainingnormal;
    itemsRemainingcourse = tempRemainingcourse;    
    
    while(j <= itemsRemainingnormal+2)                                    //change with 20
     {
        NSRange range = NSMakeRange(j, MIN(2, itemsRemainingnormal));         //change with 20
        subarraynormal = [normalscoringarray subarrayWithRange:range];
        
    //    [arrayOfNormalArrays addObject:subarraynormal];
        itemsRemainingnormal-=range.length;
        j+=range.length; 
      }
    
    NSLog(@"subarraynormal.....%@",subarraynormal);
    
    while(k <= itemsRemainingcourse+2)                                    //change with 20
    {
        NSRange range1 = NSMakeRange(k, MIN(2, itemsRemainingcourse));         //change with 20
        subarraycourse = [coursearray subarrayWithRange:range1];
  
    //    [arrayOfCourseArrays addObject:subarraycourse];
        itemsRemainingcourse-=range1.length;
        k+=range1.length;
    }
    
    NSLog(@"subarraycourse.....%@",subarraycourse);
    

    for (int i=0; i<[subarraynormal count]; i++)   
          {
                ar1=[[[subarraynormal objectAtIndex:i] objectForKey:keystring] componentsSeparatedByString:@"||"];
                ar2=[[[subarraynormal objectAtIndex:i] objectForKey:@"gdate"] componentsSeparatedByString:@"||"];
                ar3=[[[subarraynormal objectAtIndex:i] objectForKey:@"cn"] componentsSeparatedByString:@"||"];
                ar4=[[[subarraynormal objectAtIndex:i] objectForKey:@"gid"] componentsSeparatedByString:@"||"];
                
                ar5=[[[subarraycourse objectAtIndex:i] objectForKey:@"pv"] componentsSeparatedByString:@"||"];
                
                
                str1 = [ar1 objectAtIndex:3]; 
                str2 = [ar1 objectAtIndex:4];
                
                str3 = [ar2 objectAtIndex:0];
                
                str4 = [ar3 objectAtIndex:0];
                
                str5 = [ar4 objectAtIndex:0];
                
                str6 = [ar5 objectAtIndex:1];
                
                UIButton *htmlCopy = [UIButton buttonWithType:UIButtonTypeCustom];
                htmlCopy=[gameid objectAtIndex:i];
                [htmlCopy setTitle:str5 forState:UIControlStateNormal];
                
                [[coursenamearray objectAtIndex:i] setText:str4];
                [[pararray objectAtIndex:i] setText:str6];
                [[datearray objectAtIndex:i] setText:str3];
                [[grossarray objectAtIndex:i] setText:str1];
                [[netarray objectAtIndex:i] setText:str2];
                
            }
            
           tempRemainingnormal = tempRemainingnormal-2;
           tempRemainingcourse = tempRemainingcourse-2;
        
          }

  where value of  int tempRemainingnoramal = 6 and count of normalscoringarray = 7. Plz help me in correcting loop.
loop goes to infinity while getting value in subarray
===

I am trying to display values of array of limit 2 on every time 'previous' button click. I am storing the value in array according to user wish and displayed values of array in group of 2 but when i click previous button for displaying first 2 values in array my while loop goes to infinite. here is my code:

    -(void)previous
     {
     btnnext.enabled = TRUE;
     int j = 0;
     int k = 0;
    NSArray *subarraynormal = [[NSArray alloc]init];
    NSArray *subarraycourse = [[NSArray alloc]init];
   
    itemsRemainingnormal = tempRemainingnormal;
    itemsRemainingcourse = tempRemainingcourse;    
    
    while(j <= itemsRemainingnormal+2)                                    //change with 20
     {
        NSRange range = NSMakeRange(j, MIN(2, itemsRemainingnormal));         //change with 20
        subarraynormal = [normalscoringarray subarrayWithRange:range];
        
    //    [arrayOfNormalArrays addObject:subarraynormal];
        itemsRemainingnormal-=range.length;
        j+=range.length; 
      }
    
    NSLog(@"subarraynormal.....%@",subarraynormal);
    
    while(k <= itemsRemainingcourse+2)                                    //change with 20
    {
        NSRange range1 = NSMakeRange(k, MIN(2, itemsRemainingcourse));         //change with 20
        subarraycourse = [coursearray subarrayWithRange:range1];
  
    //    [arrayOfCourseArrays addObject:subarraycourse];
        itemsRemainingcourse-=range1.length;
        k+=range1.length;
    }
    
    NSLog(@"subarraycourse.....%@",subarraycourse);
    

    for (int i=0; i<[subarraynormal count]; i++)   
          {
                ar1=[[[subarraynormal objectAtIndex:i] objectForKey:keystring] componentsSeparatedByString:@"||"];
                ar2=[[[subarraynormal objectAtIndex:i] objectForKey:@"gdate"] componentsSeparatedByString:@"||"];
                ar3=[[[subarraynormal objectAtIndex:i] objectForKey:@"cn"] componentsSeparatedByString:@"||"];
                ar4=[[[subarraynormal objectAtIndex:i] objectForKey:@"gid"] componentsSeparatedByString:@"||"];
                
                ar5=[[[subarraycourse objectAtIndex:i] objectForKey:@"pv"] componentsSeparatedByString:@"||"];
                
                
                str1 = [ar1 objectAtIndex:3]; 
                str2 = [ar1 objectAtIndex:4];
                
                str3 = [ar2 objectAtIndex:0];
                
                str4 = [ar3 objectAtIndex:0];
                
                str5 = [ar4 objectAtIndex:0];
                
                str6 = [ar5 objectAtIndex:1];
                
                UIButton *htmlCopy = [UIButton buttonWithType:UIButtonTypeCustom];
                htmlCopy=[gameid objectAtIndex:i];
                [htmlCopy setTitle:str5 forState:UIControlStateNormal];
                
                [[coursenamearray objectAtIndex:i] setText:str4];
                [[pararray objectAtIndex:i] setText:str6];
                [[datearray objectAtIndex:i] setText:str3];
                [[grossarray objectAtIndex:i] setText:str1];
                [[netarray objectAtIndex:i] setText:str2];
                
            }
            
           tempRemainingnormal = tempRemainingnormal-2;
           tempRemainingcourse = tempRemainingcourse-2;
        
          }

  where value of  int tempRemainingnoramal = 6 and count of normalscoringarray = 7. Plz help me in correcting loop.