Questions tagged [decrement]

Subtracting one from the value of a variable, generally with the use of an decrement operator.

Subtracting one from the value of a variable, generally with the use of an decrement operator(--).

425 questions
2
votes
1 answer

jQuery increment and decrement button to append the applied value to a number

So I want something like this: As you can see, there's a + and - button, to which if clicked, they show respective values appended at No. of Units. All in all, what I want is: for example, if I clicked the + four times, it will show 12+4 (the +4…
anobilisgorse
  • 906
  • 2
  • 11
  • 25
2
votes
5 answers

Why aren't the co-ordinate variables incrementing and decrementing in my functions in Python?

I'm programming a text based adventure game in Python, where the player moves on a 5x5 grid and picks up items, but I'm having trouble with changing the co-ordinates of the player. coorx and coory are not incrementing and decrementing within their…
iolim5678
  • 91
  • 8
2
votes
3 answers

increment and decrement with cout in C++

I'm new to C++ and study the increment and decrement operators. So I tried this example: int x = 4; cout << ++x << " " << x++ << " " << x++ << endl << endl; cout << x << endl; It returns this weird output on C++ .NET and…
AliOsm
  • 541
  • 2
  • 6
  • 20
2
votes
3 answers

Lua for loop reduce i? Weird behavior

Can someone explain me this? for i = 1, 5 do print(i) i = i - 1 print(i) end Output is: 1 0 2 1 3 2 and so forth I exspected i to alter between 1 and 0. But obviously it keeps increasing as if I did not change it at all. What's going on? I…
Piglet
  • 27,501
  • 3
  • 20
  • 43
2
votes
3 answers

How to decrement a value in a HashMap?

So I have a playerID and numwalls for each player in a board game I'm making. Right now to remove walls when each player uses one, everyone is basically sharing walls. So I figured I should make a hashmap to hold playerID as the key and numwalls as…
FatFockFrank
  • 169
  • 1
  • 4
  • 17
2
votes
1 answer

Feeling confused with -(--a) vs --(-a) in c

Confusion with ++ and -- operator int a = 10; printf("%d\n", -(--a) ); // valid output: -9 But, problem occurs when following is used: printf("%d\n", --(-a)); // error, invalid Why?
Shahriar
  • 13,460
  • 8
  • 78
  • 95
2
votes
1 answer

Why isn't my code to update a counter working?

Why doesn't this script run when I submit a number? (The purpose is that the temp counter slowly decrements to the users input) var s,t,d; s = document.getElementById('start'); t = document.getElementById('temp'); d =…
2
votes
2 answers

do the parantheses matter?

Given this JSPerf test Why is this faster var x;var i = 1E4;var j = 1E4; for (; i-- > -1;) { x = -~x; } for (; j-- > -1;) { x = ~ - x; } Than this ? var x;var i = 1E4;var j = 1E4; for (; j-- > -1;) { x = -1 * ~x; } for (; j-- > -1;) { x = ~…
Moritz Roessler
  • 8,542
  • 26
  • 51
2
votes
2 answers

Why I encounter a NULL terminating character at start of a string when I go backwards through it?

I found the following piece of code embedded in a C++ project. The code goes backwards through a C-style string. When I saw this I thought this should result in undefined behaviour. But it seems to work perfectly: const char * hello = "Hello…
gdiquest
  • 125
  • 8
2
votes
2 answers

PHP Increment/Decrement value from xml

This is my xml. Test 1 10 12
MePo
  • 1,044
  • 2
  • 23
  • 48
2
votes
2 answers

python unclear behavior when decrementing in try-except

Is there any special behavior when decrementing a variable in the except clause? sid keeps incrementing until it first gets into the exception clause, then it just keeps the same value for the rest duration of the for loop. 7 out of 105 tries throw…
Mirko
  • 67
  • 5
2
votes
5 answers

How is this behaviour of C explained?

so I was playing around with recursion in C and I am not sure why is this happening: code A int foo(int x) { if (x==0) return 0; else return foo(--x)+x; } int main() { printf("%d\n", foo(10)); code B int foo(int x) { if (x==0) return 0; else…
infinitloop
  • 2,863
  • 7
  • 38
  • 55
2
votes
3 answers

Increment and decrements numbers

I have this text with numbers: My numbers are 04, and 0005 My numbers are 05, and 0006 My numbers are 06, and 0035 My numbers are 07, and 0007 My numbers are 08, and 0009 This is the code I always used to increment or decrement numbers in a…
Reman
  • 7,931
  • 11
  • 55
  • 97
1
vote
3 answers

the totalAmount of increment and decrement

namespace rojak2.cs { class Program { static void Main(string[] args) { ArithmeticOperators(); } static void ArithmeticOperators() { double totalAmount = 100; …
George Lim
  • 145
  • 1
  • 2
  • 8
1
vote
2 answers

Decrement array length in Javascript

I just ran across this javascript snippet: myArray.length--; What does it do exactly?
Sam Washburn
  • 1,817
  • 3
  • 25
  • 43