title: can i add key value pair to NSarray or dictionary inside a for loop?
body: <p>i want to add values to NSMutabledictionary  from a for loop with  key value pairs ?</p>
  
  <p>Currently am using this code</p>
  
  <pre><code>for(int j=0;j&lt;[array count];j++){
      for(int l=0;l&lt;array2 count] ;l++){   
            // retreive the category from plist ,then check whether its matching with "catid"
            NSString *temp=[NSString stringWithFormat:@"%@",allBookPlist[@"listbook"][j][@"cate"][l][@"categories"]];
  
             if([catId isEqualToString:temp]){    
                   // "catid" is matching with temp then ,retreive the corresponding bid from plist
                   NSString *str=[NSString stringWithFormat:@"%@",allBookPlist[@"listbook"][j][@"bid"]];
                   // add that  value "bid" and key "catid" to a mutabledictionary
                   NSMutableDictionary *m=[[NSMutableDictionary alloc]init];
                   [m setValue:str forKey:catId];
              }
       }
  }
  </code></pre>
  
  <p>The result is each time the value of the final dictionary "m" get replaced by latest values,but i want all values toghether?</p>
  
  <p><img src="https://i.stack.imgur.com/L3lLu.png" alt="enter image description here"> iam trying to get an output like this</p>