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
3
votes
2 answers

Infinite loop when using cmpq and je

I'm decrementing RAX on each iteration. If RAX is zero, the program should change flow. # AT&T syntax start_calc_factorial: decq %rax cmpq $0, %rax je quit_calc_factorial mulq %rcx jmp start_calc_factorial However, the program never…
Dutchman
  • 180
  • 7
3
votes
3 answers

How do I create a function which will return a dictionary with two functions in that will increment/decrement a count in Python?

I've been tasked with creating a function "make_counter" which takes a number as its only argument. It should return a dictionary containing two functions that can be invoked to increment and decrement the number and then return it. The behaviour…
3
votes
2 answers

Struggling with basic dataframe manipulation (Python)

I am a complete newbie at Python, and I'm struggling despite having Googled for quite a while. I know it should not be this difficult. I have a Dataframe called abc that looks like this: PO_DATE PO_ITEM_NUMBER PO_PRICE …
Clare
  • 49
  • 5
3
votes
5 answers

How to decrement several variables in C++in a single line statement?

Edit: I replaced the phrase 'in one line' by 'in a single line statement' since this is what I was looking for Let's say we have the following variables at hand: int a = 5; int b = 9; Is there a way to compress this ... a--; b--; ... into in a…
Diggi55
  • 174
  • 8
3
votes
3 answers

Increment / decrement button In ExtJS

Is there a button in ExtJS with increment/decrement feature (something like that)? I have some numberfields with values that are usually incremented/decremented when edited and this button would be very helpful. Note that it is not critical for me…
Giku Promitt
  • 610
  • 1
  • 5
  • 19
3
votes
5 answers

Why is `x-- > 0` not undefined behaviour, while `x = x--` is?

As everyone knows, this loops through zero: while (x-- > 0) { /* also known as x --> 0 */ printf("x = %d\n", x); } But x = x-- yields undefined behaviour. Both examples need some 'return' value of x--, which is not there I guess. How can it be…
user142019
3
votes
2 answers

PHP decrement NULL value issue

I have noticed if a value is null i can increment it by one using ++$value but its not true about decrement , meaning --$value would return null , why? $value = null; echo ++$value; // 1 echo --$value; // null (I'm expecting -1)
alex
  • 7,551
  • 13
  • 48
  • 80
3
votes
1 answer

Does a change of value of a global variable by a function affect the order of addition?

I have tried the following code and got confused: #include int m=3; int f(void) { m--; return m; } int main() { m=f()+m; //as + operator is executed from left to right, it is okay that m=2+2 printf("%d\n", m); //m=4, as…
Preetom Saha Arko
  • 2,588
  • 4
  • 21
  • 37
3
votes
3 answers

Why is ++ and -- only used before and after variables?

I'm reading "The C programming language" by Brian W. Kernighan and Dennis M. Ritchie, on page 46 its states that "The increment and decrement operators can only be applied to variables; an expression like (i+j)++ is illegal". Why can't it be used…
Arlind Hajredinaj
  • 8,380
  • 3
  • 30
  • 45
3
votes
4 answers

Javascript for loop with iterator In the middle and decrement operator to the left of i?

For a non-recursive example of a factorial function I found this example and am having a little difficulty tracing through the code: function fact(x) { if(x == 0) { return 1; } if(x < 0 ) { return undefined; } for(var i…
phizzy
  • 936
  • 9
  • 26
3
votes
2 answers

Find numbers in a string and decrement them

I have an HTML page that lists a long index of topics and page numbers. I want to find all the page numbers and their anchor tag links and decrement the page numbers by 1. Here is an example line in the HTML:

breakeven volume (BEV),…

John Gayle
  • 43
  • 3
3
votes
1 answer

The history of 1- and 1+

I was in #lisp on freenode recently, and someone mentioned the existence of '1-' and 1+. Knowing about these functions left me wondering why they exist. Were they originally created for perormance reasons like the related -- and ++ of C/C++, or was…
Faheem Mitha
  • 6,096
  • 7
  • 48
  • 83
3
votes
1 answer

Simple increment/decrement counter

I would like to make a simple counter in PowerShell. It must prompt the user whether they'd like a higher or lower number. The starting number must be 0, and it can't be lower than zero or higher than 10. If the user wants a higher number, it must…
ScriptingBerry
  • 655
  • 4
  • 7
  • 12
2
votes
2 answers

Is the behaviour of this statement of assignment and decrementation well defined?

The following statement does not really make sense: value = value--; I accidentially wrote this instead of just value-- or value = value-1 . But since it worked on my machine as intended, the error was not noticed. Now I want to know, if this…
rkgghz
  • 456
  • 8
  • 19
2
votes
2 answers

stopping counter at 0

I have two functions that increment and decrement number of items by 1, but when I decrement I want to stop at 0? this are the functions const addToCart = (productId) => { setCartItems((prev) => ({ ...prev, [productId]:…