Questions tagged [increment]

DO NOT USE THIS TAG ALONE. Use with a language tag like [javascript] or [python]. Adding one to the value of a variable, generally with the use of an increment operator.

Adding one to the value of a variable, generally with the use of an increment operator.

3172 questions
900
votes
10 answers

Behaviour of increment and decrement operators in Python

I notice that a pre-increment/decrement operator can be applied on a variable (like ++count). It compiles, but it does not actually change the value of the variable! What is the behavior of the pre-increment/decrement operators (++/--) in Python?…
Ashwin Nanjappa
  • 68,458
  • 72
  • 198
  • 283
880
votes
7 answers

Python integer incrementing with ++

I've always laughed to myself when I've looked back at my VB6 days and thought, "What modern language doesn't allow incrementing with double plus signs?": number++ To my surprise, I can't find anything about this in the Python docs. Must I really…
Znarkus
  • 21,120
  • 20
  • 71
  • 104
854
votes
14 answers

Why are these constructs using pre and post-increment undefined behavior?

#include int main(void) { int i = 0; i = i++ + ++i; printf("%d\n", i); // 3 i = 1; i = (i++); printf("%d\n", i); // 2 Should be 1, no ? volatile int u = 0; u = u++ + ++u; printf("%d\n", u); // 1 u = 1; …
PiX
  • 9,147
  • 4
  • 17
  • 11
500
votes
26 answers

Why does this go into an infinite loop?

I have the following code: public class Tests { public static void main(String[] args) throws Exception { int x = 0; while(x<3) { x = x++; System.out.println(x); } } } We know he should have…
The Student
  • 25,055
  • 64
  • 149
  • 253
167
votes
5 answers

Increment a database field by 1

With MySQL, if I have a field, of say logins, how would I go about updating that field by 1 within a sql command? I'm trying to create an INSERT query, that creates firstName, lastName and logins. However if the combination of firstName and…
Matt
  • 3,838
  • 9
  • 36
  • 61
166
votes
9 answers

R: += (plus equals) and ++ (plus plus) equivalent from c++/c#/java, etc.?

Does R have a concept of += (plus equals) or ++ (plus plus) as c++/c#/others do?
SFun28
  • 32,209
  • 43
  • 123
  • 233
163
votes
4 answers

Ruby: How to iterate over a range, but in set increments?

So I'm iterating over a range like so: (1..100).each do |n| # n = 1 # n = 2 # n = 3 # n = 4 # n = 5 end But what I'd like to do is iterate by 10's. So in stead of increasing n by 1, the next n would actually be 10, then 20, 30,…
Shpigford
  • 22,682
  • 52
  • 149
  • 235
153
votes
6 answers

++someVariable vs. someVariable++ in JavaScript

In JavaScript you can use ++ operator before (pre-increment) or after the variable name (post-increment). What, if any, are the differences between these ways of incrementing a variable?
Derek Adair
  • 20,298
  • 31
  • 92
  • 133
144
votes
8 answers

Can a for loop increment/decrement by more than one?

Are there other ways to increment a for loop in Javascript besides i++ and ++i? For example, I want to increment by 3 instead of one. for (var i = 0; i < myVar.length; i+3) { //every three }
brentonstrine
  • 17,958
  • 23
  • 61
  • 112
140
votes
11 answers

The "++" and "--" operators have been deprecated Xcode 7.3

I am looking at Xcode 7.3 notes and I notice this issue. The ++ and -- operators have been deprecated Could some one explain why it is deprecated? And am I right that in new version of Xcode now you going to use instead of ++ this x +=…
Oleg Gordiichuk
  • 13,891
  • 5
  • 52
  • 91
139
votes
10 answers

Pointer expressions: *ptr++, *++ptr and ++*ptr

Recently I have come across this problem which I am unable to understand by myself. What do these three Expressions REALLY mean? *ptr++ *++ptr ++*ptr I have tried Ritchie. But unfortunately was unable to follow what he told about these 3…
allocated
  • 1,613
  • 3
  • 11
  • 15
122
votes
1 answer

Increment a value in Postgres

I'm a little new to postgres. I want to take a value (which is an integer) in a field in a postgres table and increment it by one. For example if the table 'totals' had 2 columns, 'name' and 'total', and Bill had a total of 203, what would be the…
greatwitenorth
  • 1,778
  • 2
  • 16
  • 19
121
votes
16 answers

Is there a difference between x++ and ++x in java?

Is there a difference between ++x and x++ in java?
erickreutz
  • 2,569
  • 3
  • 20
  • 18
112
votes
8 answers

Why does c = ++(a+b) give compilation error?

After researching, I read that the increment operator requires the operand to have a modifiable data object: https://en.wikipedia.org/wiki/Increment_and_decrement_operators. From this I guess that it gives compilation error because (a+b) is a…
dng
  • 1,245
  • 1
  • 5
  • 10
110
votes
14 answers

What is a method that can be used to increment letters?

Does anyone know of a Javascript library (e.g. underscore, jQuery, MooTools, etc.) that offers a method of incrementing a letter? I would like to be able to do something like: "a"++; // would return "b"
andyzinsser
  • 2,233
  • 2
  • 15
  • 17
1
2 3
99 100