Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7599131
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T22:35:06+00:00 2026-05-30T22:35:06+00:00

//loop over alphabet and set the key values for addressbook for(char a = ‘a’;

  • 0
//loop over alphabet and set the key values for addressbook
for(char a = 'a'; a <= 'z'; a++){
        addressbook=[[NSMutableDictionary alloc] init];
        [addressbook setValue:@"$" forKey:[NSString stringWithFormat:@"%c", a]];
        NSLog(@"%@ value, %@ key", @"$",[NSString stringWithFormat:@"%c", a]);

    }
}
//display the key values of addressbook
  for(NSString *key in addressbook){
    NSLog(@"%@ key, %@ value", key,[addressbook objectForKey:key]);
}  

The first NSLog shows a working for loop

2012-02-27 16:02:31.886 Adresboek[4692:503] $ value, a key
2012-02-27 16:02:31.889 Adresboek[4692:503] $ value, b key
2012-02-27 16:02:31.890 Adresboek[4692:503] $ value, c key
.
.
.
2012-02-27 16:02:31.911 Adresboek[4692:503] $ value, x key
2012-02-27 16:02:31.912 Adresboek[4692:503] $ value, y key
2012-02-27 16:02:31.913 Adresboek[4692:503] $ value, z key

The second NSLog shows only the last element

2012-02-27 16:02:31.914 Adresboek[4692:503] z key, $ value
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T22:35:07+00:00Added an answer on May 30, 2026 at 10:35 pm

    Well, sure. You’re creating a new NSMutableDictionary every time around the loop. Move the creation to before the loop.

    for(char a = 'a'; a <= 'z'; a++){
            addressbook=[[NSMutableDictionary alloc] init];
    
    addressbook=[[NSMutableDictionary alloc] init];
    for(char a = 'a'; a <= 'z'; a++){
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

If I want to loop over a Dictionary(Key, Value)... why cant I add a
I am trying to loop over some values to insert data into a DB
I need to loop over my array and set all the vars to false
I have a loop which creates a key (based on the alphabet) and value
I'm trying to loop over a set of results using MySQLi and the bind
I'm trying to loop over distinct values over a dictionary list: So I have
I'm wondering if there's a way to loop over a values specified in the
I'm trying to loop over a set of results using MySQLi and the bind
I'd like to loop over an associative array and print out the key /
I want to loop over the contents of a text file and do a

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.