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

Python pandas decrease backfill until reach a certain number based on interval

I have the following dataframe called df, date flag1 flag2 flag3 flag4… 2020-12-31 2021-01-01 2021-01-02 1 2021-01-03 2021-01-04 2021-01-05 1 2021-01-06 …
anarchy
  • 3,709
  • 2
  • 16
  • 48
2
votes
8 answers

Explain, please, these ++ and -- operations

Why this code outputs 3, not 2? var i = 1; i = ++i + --i; console.log(i); I expected: ++i // i == 2 --i // i == 1 i = 1 + 1 // i == 2 Where I made mistake?
Sergey Metlov
  • 25,747
  • 28
  • 93
  • 153
2
votes
3 answers

Decrement by a certain amount on java

i'm trying to create a program where the number that the user has input would decrease by a certain amount. something that would like this: Update by (Increment/Decrement):decrement Enter starting number:15 Enter update number:3 Enter end…
coderx
  • 23
  • 5
2
votes
3 answers

JavaScript 99Bottles - Infinite Loop

(I already know that this isn't the most elegant solution to the 99 bottles code challenge, but I'd really like to know how not to repeat this mistake in the future.) When this runs in the console it repeats the (count === 0) condition and repeats…
2
votes
1 answer

JQuery Increment/Decrement value depending on selected checkboxes

I am mostly there but cant seem to crack this, I have a simple form with check boxes, form#bookingsToDelete( action='/list/batchDelete' method='POST' autocomplete='off' ) tbody …
ZADorkMan
  • 301
  • 4
  • 19
2
votes
3 answers

Why does --string::end() compile but --string.size() does not?

The code std::string str{ "foo" }; auto lastCharIndex{ --str.size() }; creates a compiler error lvalue required as decrement operand but auto lastCharIterator{ --str.end() }; does not. Why is this?
swaltek
  • 143
  • 5
2
votes
1 answer

Decrementing an ordered list

I have a ordered list in an html document, you know, like
  1. item one
  2. item two
which displays, obviously, as 1. item one 2. item two I want to make these numbers countdown rather than up. Anyway to do this using…
rapidash
  • 278
  • 3
  • 14
2
votes
2 answers

How to decrement a for loop in JavaScript based upon a number that a user enters into a prompt?

I want the loop to count down starting with the user's input number all the way down to 0. For example, if the user puts in 10, it will count down from 10 to 0. I think I'm close but need a little help. var userNum = Number(window.prompt("Enter…
Aj96
  • 187
  • 8
2
votes
2 answers

Subtracting 1 from a value and storing it in another variable

I vaguely remember running into this problem before, but I'm wondering if this just doesn't work in PHP: echo $counter; // outputs 4 $output = $counter--; echo $output; // outputs 4 If I do something like: $output = $counter - 1; I have no…
NightHawk
  • 3,633
  • 8
  • 37
  • 56
2
votes
2 answers

New to React, Increment/Decrement in shopping cart

I'm doing this small project and I'm stuck, but not that much I hope! I've pasted all code so you can see the whole picture so to speak. What I wanna do is to make the onClick event just change the actual item in the cart. As of now, when you press…
user8151168
2
votes
2 answers

Why is putting an arbitrary number of pre-increment/decrement operators together possible in C++?

Today, I noticed that it is possible to do something like this (C++): int x = 3; ++++x; // Correct! ----x; // Correct, too! ++++++x; // x is now 6 That means we can put as many as pre-increments and pre-decrements together. Am I right? I know it…
MAChitgarha
  • 3,728
  • 2
  • 33
  • 40
2
votes
1 answer

Does (--n) equal (n - 1)?

I've recently started trying to learn C & was doing an exercise that involved creating a recursive factorial function. Why does the following print out an answer of 24? #include int factorial(int n); int main(void) { int n = 5; …
pickle323
  • 653
  • 4
  • 12
2
votes
3 answers

jQuery Decremental Loop

I need to make a jQuery incremental/decremental loop. So I'm posting the vanilla JavaScript here, Can anyone change this into jQuery code for me please. var incomeTicker = 60; window.setInterval(function(){ if (incomeTicker > 0){ …
2
votes
4 answers

C++ Iterator dereference and prefix increment/decrement style? Is *--Iter ok style wise?

In coding with C++ iterators if you wanted to get the previous value to what an iterator points to would you write: *--Iter or would you think it better to add parentheses like so: *(--Iter) ?
Paul Caheny
  • 1,281
  • 3
  • 11
  • 16
2
votes
3 answers

Why was arg = args[n++] more efficient than 2 seperate statements in earlier compilers?

From the Book "Core Java for the Impatient", Chapter "increment and decrement operators" String arg = args[n++]; sets arg to args[n], and then increments n. This made sense thirty years ago when compilers didn’t do a good job optimizing code. …
wilmaed
  • 41
  • 3