Welcome to the Java Programming Forums


The professional, friendly Java community. 21,500 members and growing!


The Java Programming Forums are a community of Java programmers from all around the World. Our members have a wide range of skills and they all have one thing in common: A passion to learn and code Java. We invite beginner Java programmers right through to Java professionals to post here and share your knowledge. Become a part of the community, help others, expand your knowledge of Java and enjoy talking with like minded people. Registration is quick and best of all free. We look forward to meeting you.


>> REGISTER NOW TO START POSTING


Members have full access to the forums. Advertisements are removed for registered users.

Results 1 to 4 of 4

Thread: Issues with changing values in for loops

  1. #1
    Junior Member
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Issues with changing values in for loops

    Edit: solved

    I am trying to use a for loop with the for(type *:*) syntax. I started in C++ so have never used this syntax. I am attempting to change some values inside this array but the values do not seem to be staying after exiting the loop.

    for(char eachChar : msgArr)
    {
    	System.out.println(eachChar);
    	eachChar = (char) (eachChar + 1);
    	System.out.println(eachChar);
    }
    System.out.println(msgArr);

    If message array starts as "test" the output will be:
    t
    u
    e
    f
    s
    t
    t
    u
    test

    The expected output should be uftu at the last line, but instead continues to say test! Am I missing something silly or am I misunderstanding this for loop syntax.

    I appreciate any assistance!

    --- Update ---

    Ok eachChar is local variable to the for loop! I used a vanilla loop and that worked.
    Last edited by ryan.boykin; August 1st, 2013 at 12:57 PM. Reason: Solved


  2. #2
    Member
    Join Date
    Dec 2011
    Location
    United States
    Posts
    94
    My Mood
    Amused
    Thanks
    5
    Thanked 8 Times in 8 Posts

    Default Re: Issues with changing values in for loop

    So does that mean you have solved this problem then?

  3. The Following User Says Thank You to elisha.java For This Useful Post:

    ryan.boykin (August 1st, 2013)

  4. #3
    Junior Member
    Join Date
    Aug 2013
    Posts
    3
    Thanks
    2
    Thanked 0 Times in 0 Posts

    Default Re: Issues with changing values in for loop

    Yes I'll change it solved.

  5. #4
    Grand Poobah
    Join Date
    Mar 2011
    Posts
    1,545
    My Mood
    Grumpy
    Thanks
    0
    Thanked 167 Times in 158 Posts

    Default Re: Issues with changing values in for loops

    Quote Originally Posted by ryan.boykin View Post
    I used a vanilla loop
    What the fark is a vanilla loop?
    Improving the world one idiot at a time!

Similar Threads

  1. help with defining a changing variable within a loop
    By uswhovian in forum What's Wrong With My Code?
    Replies: 7
    Last Post: March 9th, 2013, 11:30 AM
  2. help with defining a changing variable within a loop
    By uswhovian in forum Loops & Control Statements
    Replies: 3
    Last Post: March 9th, 2013, 10:30 AM
  3. Replies: 0
    Last Post: July 5th, 2012, 08:24 AM
  4. JTextPane changing text color issues
    By donnierisk in forum What's Wrong With My Code?
    Replies: 1
    Last Post: April 30th, 2012, 11:29 AM
  5. values of variables changing despite not modifying them
    By AndyKow in forum What's Wrong With My Code?
    Replies: 1
    Last Post: October 9th, 2011, 12:39 PM

Tags for this Thread