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
19
votes
1 answer

Incrementing function in an array

The increment function in the following snippet increments the fourth element, the fifth element, then the last element (20) My goal is for it to increment every number value from the fourth element onward, skipping letters. This is the line that…
Koala7
  • 1,340
  • 7
  • 41
  • 83
19
votes
6 answers

Java increment and assignment operator

I am confused about the post ++ and pre ++ operator , for example in the following code int x = 10; x = x++; sysout(x); will print 10 ? It prints 10,but I expected it should print 11 but when I do x = ++x; instead of x = x++; it will print…
user3803547
  • 205
  • 1
  • 2
  • 5
19
votes
6 answers

using Notepad++ how can i make a macro type situation in which a number increments?

for example i have about 500 lines. in the beginning of each line i want to add a number. so in line 1 i would want "1)" and then line 2 i would want "2)" i know i can do a macro in n++, but it wouldn't be incremental. is there any possible way to…
Bilal
  • 193
  • 1
  • 1
  • 4
19
votes
5 answers

Increment variable by more than 1?

Here's my script : function itemQuantityHandler(operation, cart_item) { var v = cart_item.quantity; //add one if (operation === 'add' && v < settings.productBuyLimit) { v++; } //substract one if (operation === 'subtract' && v > 1)…
larin555
  • 1,669
  • 4
  • 28
  • 43
18
votes
2 answers

Order of evaluation and undefined behaviour

Speaking in the context of the C++11 standard (which no longer has a concept of sequence points, as you know) I want to understand how two simplest examples are defined. int i = 0; i = i++; // #0 i = ++i; // #1 There are two topics on SO…
Kolyunya
  • 5,973
  • 7
  • 46
  • 81
17
votes
2 answers

Increment in function overwritten by +=

A method called in a ternary operator increments a variable and returns a boolean value. When the function returns false the value is reverted. I expected the variable to be 1 but am getting 0 instead. Why? public class Main { public int…
17
votes
2 answers

Blue number in Chrome Dev Console?

In javascript I have a variable that I push to console.log then increment it and push it to the log again, which shows the below in the Chrome Dev Tools. This variable has done some freaky stuff, like if I try to use the += operator to add to it,…
Cains
  • 883
  • 2
  • 13
  • 23
17
votes
5 answers

C# - increment number and keep zeros in front

I need to make a 40 digit counter variable. It should begin as 0000000000000000000000000000000000000001 and increment to 0000000000000000000000000000000000000002 When I use the int class, it cuts off all the zeros. Problem is I need to increment…
blizz
  • 4,102
  • 6
  • 36
  • 60
16
votes
3 answers

Thread-safe way to increment and return an integer in Delphi

In a single-threaded application I use code like this: Interface function GetNextUID : integer; Implementation function GetNextUID : integer; const cUID : integer = 0; begin inc( cUID ); result := cUID; …
Marek Jedliński
  • 7,088
  • 11
  • 47
  • 57
16
votes
4 answers

Why the increment of an integer on C# is executed after a function return its value?

Why this two functions return different values? When I call this function passing 0 as parameter it returns 1 public static int IncrementByOne(int number) { return (number + 1); } However, when I call this function passing 0 as parameter it…
Esteban Verbel
  • 738
  • 2
  • 20
  • 39
16
votes
9 answers

What is the difference between += and =+?

What is the difference between += and =+? Specifically, in java, but in general also.
Java Man
  • 163
  • 1
  • 4
16
votes
4 answers

How to increment variable names/Is this a bad idea

In Python, if I were to have a user input the number X, and then the program enters a for loop in which the user inputs X values, is there a way/is it a bad idea to have variable names automatically increment? ie: user inputs '6' value_1 = ... …
tom
  • 161
  • 1
  • 1
  • 3
16
votes
8 answers

How to increment the number in a String by 1?

I have a below String as - String current_version = "v2"; And here version can be either of these string as well - v3 or v4 or v10 or v100 or v500 or v1000 Now I am looking to increment the current_version from v2 to v3. Meaning I always need to…
user2467545
16
votes
1 answer

How to make a pointer increment by 1 byte, not 1 unit

I have a structure tcp_option_t, which is N bytes. If I have a pointer tcp_option_t* opt, and I want it to be incremented by 1, I can't use opt++ or ++opt as this will increment by sizeof(tcp_option_t), which is N. I want to move this pointer by 1…
misteryes
  • 2,167
  • 4
  • 32
  • 58
16
votes
2 answers

Incrementing a number in a loop in plpgsql

I couldn't find this immediately from the examples. I want to increment a variable in a loop, in a function. For instance: DECLARE iterator float4; BEGIN iterator = 1; while iterator < 999 ..... iterator ++; END; How would…
CQM
  • 42,592
  • 75
  • 224
  • 366