Home Accessibility Courses Twitter The Mouth Facebook Resources Site Map About Us Contact
 
Python and Tcl - public course schedule [here]
Private courses on your site - see [here]
Please ask about maintenance training for Perl, PHP, Lua, etc
 
Incrementing a variable in Java - Pre and Post Increment

Java (and C, Perl and PHP) supports the ++ operator to increment a variable - in other word, do add 1 to the value it holds and save the reult back in the same place.

You can write
  counter++;
or
  ++counter;
and as statemnets on their own, they'll do the same thing.

However, embed them with another statement and it does make a differene.
  another = summat++;
is different to
  another = ++summat;

Both of these increment the variable summat, but what get stored into another will differ.
• With ++ after the variable name, the extra 1 is added after the other uses of that variable in the line - in other words, another gets set to the original value of summat
• With ++ before the variable name, the extra 1 is added before the other uses of that variable in the line - in other words, another gets set to the new value of summat

With the ++ in front, it's know as pre-increment - increment before other use
With the ++ behind, it's know as post-increment - increment after other use

Sample of that it use - [here] from the current Java course
(written 2014-12-08, updated 2014-12-09)

 
Associated topics are indexed as below, or enter http://melksh.am/nnnn for individual articles
J703 - Java - Variables
  [4324] Learning to program - variables and constants - (2014-11-22)
  [3917] BODMAS - the order a computer evaluates arithmetic expressions - (2012-11-09)
  [3365] Turning bright delegates into bright and knowledgable ones - (2011-07-21)
  [3278] Do I need to initialise variables - programming in C, C++, Perl, PHP, Python, Ruby or Java. - (2011-05-05)
  [3041] Java - basic rules for arithmetic, variables and conversion - (2010-11-10)
  [3038] Setting up individual variables, and arrays, in Java - some commented examples - (2010-11-09)
  [2153] Class Loading and Variable Conversion in Java - (2009-05-02)
  [2148] Variable scope in Java Servlets and other web applications - (2009-05-01)
  [1448] Question on division (Java) - Also Perl, PHP, Python ... - (2007-11-28)
  [127] Conversion and coercion in Java - (2004-11-22)


Back to
Python base and inherited classes, test harness and unit testing - new examples
Previous and next
or
Horse's mouth home
Forward to
A behaviour driven example of writing a Java program
Some other Articles
When I am old, what will worry me?
Taking my life in my hands in Swansea
Arrays in Java - an introduction for newcomers
A behaviour driven example of writing a Java program
Incrementing a variable in Java - Pre and Post Increment
Python base and inherited classes, test harness and unit testing - new examples
Politics and the railway the connects Wiltshire
My first official measure - Passenger Entrys and Exits - revisited 9 years later
Segmentation Fault, Segmentation Violation, Bus Error, Stack Smashing
Command line and file handling in C
4759 posts, page by page
Link to page ... 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, 26, 27, 28, 29, 30, 31, 32, 33, 34, 35, 36, 37, 38, 39, 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 50, 51, 52, 53, 54, 55, 56, 57, 58, 59, 60, 61, 62, 63, 64, 65, 66, 67, 68, 69, 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 80, 81, 82, 83, 84, 85, 86, 87, 88, 89, 90, 91, 92, 93, 94, 95, 96 at 50 posts per page


This is a page archived from The Horse's Mouth at http://www.wellho.net/horse/ - the diary and writings of Graham Ellis. Every attempt was made to provide current information at the time the page was written, but things do move forward in our business - new software releases, price changes, new techniques. Please check back via our main site for current courses, prices, versions, etc - any mention of a price in "The Horse's Mouth" cannot be taken as an offer to supply at that price.

Link to Ezine home page (for reading).
Link to Blogging home page (to add comments).

You can Add a comment or ranking to this page

© WELL HOUSE CONSULTANTS LTD., 2019: 404 The Spa • Melksham, Wiltshire • United Kingdom • SN12 6QL
PH: 01225 708225 • EMAIL: info@wellho.net • WEB: http://www.wellho.net • SKYPE: wellho

PAGE: http://www.wellho.net/mouth/4345_Inc ... ement.html • PAGE BUILT: Sat May 27 16:49:10 2017 • BUILD SYSTEM: WomanWithCat