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.


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

Results 1 to 2 of 2

Thread: post increment

  1. #1
    Join Date
    Jan 2012
    My Mood
    Thanked 0 Times in 0 Posts

    Default post increment

    hello frnsss..

    i was using the post increment in the while loop like this

    int a= 0;
    //body of the loop

    when this will executes then it first increment the value of a and then do the comparison ..
    but when i use the same in switch like this ..

    int a=0;
    case 1: System.out.print("hello");
    default: System.out.print("deflt");

    when this code executes it executes only default part .. which means it do not increments the value of a in switch..
    how this behavior is different in switch and while statements when i use the post increment .. please explain ... this behavior of post increment in these cases ..


  2. #2
    Junior Member psabbate's Avatar
    Join Date
    Aug 2012
    My Mood
    Thanked 5 Times in 4 Posts

    Default Re: post increment

    That's not ok. Post increment first evaluate the variable, then increments.

    So, if you have

    int a=0

    System.out .... (a++) //Print 0
    System.out .... (++a) //Print 2
    Everyone wants to go to heaven ... but nobody wants to die

    Nissi Group, Servicios IT,
    Diseņo Web, Desarrollo de Software, SEO,

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

    deependeroracle (November 12th, 2012)

Similar Threads

  1. boolean for increment method
    By daitobu in forum Object Oriented Programming
    Replies: 6
    Last Post: August 28th, 2012, 09:09 PM
  2. Increment operators on char
    By ueg1990 in forum Java Theory & Questions
    Replies: 2
    Last Post: July 19th, 2012, 12:26 AM
  3. [SOLVED] How To Increment Array Elements
    By Nuggets in forum Java Theory & Questions
    Replies: 15
    Last Post: April 1st, 2012, 12:10 PM
  4. Increment a date
    By colerelm in forum Java Theory & Questions
    Replies: 1
    Last Post: September 30th, 2011, 05:57 AM
  5. [SOLVED] Increment Statements Difference
    By chronoz13 in forum Java Theory & Questions
    Replies: 4
    Last Post: May 10th, 2011, 01:51 PM