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

    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:
            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(" ");

  2. #2
    jim829 is offline Senior Member
    Join Date
    Jan 2013
    Northern Virginia, United States
    Rep Power

    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.

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