Results 1 to 2 of 2
  1. #1
    coolman50544 is offline Member
    Join Date
    Apr 2014
    Location
    Miami, FL
    Posts
    47
    Rep Power
    0

    Default Why won't this variable increment!

    I am trying to increment a variable named counterVariable each time it goes through a for enhanced loop. It is stuck on 0. Could someone explain why and how to fix this?
    Java Code:
    valuesProcessor:
            for(String[] row : values)
            {
                for(String col : row)
                {
                    int counterVariable = 0;
                    if(col == null)
                        break valuesProcessor;
                    else if(counterVariable == 0)
                        System.out.printf("%s", col);
                    else if(counterVariable == 1)
                        System.out.printf("%10s", col);
                    else if(counterVariable == 2)
                        System.out.printf("%130s", col);
                    else if(counterVariable == 3)
                        System.out.printf("%1330s", col);
                    System.out.print(" ");
                    counterVariable++;
                }
                System.out.println();
            }

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Location
    Northern Virginia, United States
    Posts
    4,036
    Rep Power
    6

    Default Re: Why won't this variable increment!

    Well, for one thing, you keep resetting it to 0 in the inner loop. And to complicate matters, when you exit the inner loop, the variable goes out of scope.


    Regards,
    Jim
    The JavaTM Tutorials | SSCCE | Java Naming Conventions
    Poor planning on your part does not constitute an emergency on my part

Similar Threads

  1. Post increment
    By bigo005 in forum New To Java
    Replies: 5
    Last Post: 01-11-2014, 03:58 AM
  2. Date increment help
    By jeffrey159 in forum New To Java
    Replies: 0
    Last Post: 10-18-2013, 04:19 PM
  3. Increment Counter for ID
    By blkshrk81 in forum New To Java
    Replies: 6
    Last Post: 12-01-2010, 02:25 AM
  4. Increment Operator Example
    By abimaran in forum New To Java
    Replies: 10
    Last Post: 11-03-2009, 05:45 PM
  5. Increment a Variable
    By rhm54 in forum New To Java
    Replies: 2
    Last Post: 06-14-2008, 03:57 AM

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •