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.

3520 questions
1043
votes
11 answers

Behaviour of increment and decrement operators in Python

How do I use pre-increment/decrement operators (++, --), just like in C++? Why does ++count run, but not change the value of the variable?
Ashwin Nanjappa
  • 76,204
  • 83
  • 211
  • 292
988
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…
Markus Hedlund
  • 23,374
  • 22
  • 80
  • 109
906
votes
15 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,705
  • 4
  • 19
  • 11
508
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
  • 27,520
  • 68
  • 161
  • 264
250
votes
7 answers

What is the difference between i++ and ++i in C#?

I've seen them both being used in numerous pieces of C# code, and I'd like to know when to use i++ and when to use ++i? (i being a number variable like int, float, double, etc).
Dlaor
  • 2,900
  • 3
  • 17
  • 14
208
votes
7 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
  • 21,846
  • 31
  • 97
  • 134
202
votes
10 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?
Suraj
  • 35,905
  • 47
  • 139
  • 250
187
votes
9 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
  • 21,694
  • 25
  • 74
  • 120
182
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
  • 4,140
  • 9
  • 40
  • 64
179
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
  • 24,748
  • 58
  • 163
  • 252
166
votes
1 answer

How to increment value in PostgreSQL?

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
  • 2,241
  • 2
  • 19
  • 21
156
votes
11 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,295
  • 3
  • 13
  • 16
147
votes
12 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
  • 15,240
  • 7
  • 60
  • 100
140
votes
18 answers

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

Is there a difference between ++x and x++ in java?
erickreutz
  • 2,779
  • 3
  • 21
  • 18
131
votes
16 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,463
  • 2
  • 18
  • 18
1
2 3
99 100