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
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
381
votes
10 answers

What does "!--" do in JavaScript?

I have this piece of code (taken from this question): var walk = function(dir, done) { var results = []; fs.readdir(dir, function(err, list) { if (err) return done(err); var pending = list.length; if…
Kieran E
  • 3,616
  • 2
  • 18
  • 41
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
72
votes
5 answers

Decrementing for loops

I want to have a for loop like so: for counter in range(10,0): print counter, and the output should be 10 9 8 7 6 5 4 3 2 1
pandoragami
  • 5,387
  • 15
  • 68
  • 116
55
votes
7 answers

Decrement value in mysql but not negative

I want to decrement a value when user delete it in php and mysql. I want to check not to go below than 0. If value is 0 then do not decrement. mysql_query("UPDATE table SET field = field - 1 WHERE id = $number"); If field is 0 then do not do…
user2244804
48
votes
1 answer

Why don't multiple decrement operators work in C when they work in C++?

Looking at this question and trying out some of the code: int x = 100; while ( 0 <-------------------- x ) { printf("%d ", x); } I attempted to compile with gcc and got the following error: file.c: In function 'main': file:c:10:27: error:…
MD XF
  • 7,860
  • 7
  • 40
  • 71
46
votes
5 answers

Decrement index in a loop after Swift C-style loops deprecated

How would you express a decrementing indexed loop in Swift 3.0, where the syntax below is not valid any more? for var index = 10 ; index > 0; index-=1{ print(index) } // 10 9 8 7 6 5 4 3 2 1
netshark1000
  • 7,245
  • 9
  • 59
  • 116
32
votes
1 answer

How do I increment or decrement a number in Common Lisp?

What is the idiomatic Common Lisp way to increment/decrement numbers and/or numeric variables?
Jabavu Adams
  • 2,348
  • 3
  • 18
  • 16
29
votes
4 answers

Why do the INC and DEC instructions *not* affect the Carry Flag (CF)?

Why do the x86 instruction INC (increment) and DEC (decrement) not affect the CF (carry flag) in FLAGSREGISTER?
mohammad mahed
  • 511
  • 2
  • 6
  • 11
28
votes
6 answers

Decrementing for loop in coffeescript

I know how to do a incrementing for loop in coffeescript such as: Coffeescript: for some in something Generated Javascript: for (_i = 0, _len = something.length; _i < _len; _i++) How do I create a decrementing for loop similar to this in…
John
  • 4,362
  • 5
  • 32
  • 50
27
votes
5 answers

Is it safe to put increment/decrement operators inside ternary/conditional operators?

Here's an example #include using namespace std; int main() { int x = 0; cout << (x == 0 ? x++ : x) << endl; //operator in branch cout << "x=" << x << endl; cout << (x == 1 || --x == 0 ? 1 : 2) << endl; //operator in…
jozxyqk
  • 16,424
  • 12
  • 91
  • 180
26
votes
1 answer

What good is the NERFIN loop operation in LOLCODE?

What the spec says on the subject: Iteration loops have the form: IM IN YR
JB.
  • 40,344
  • 12
  • 79
  • 106
17
votes
2 answers

MySQL Auto Increment Columns on TRANSACTION, COMMIT, and ROLLBACK

When using MySQL START TRANSACTION and the decision is made by MySQL to roll back - In the case that a table had an AUTO_INCREMENT column - does the column get... decremented during the roll back? Or should it? I am having some issues where the…
user1502852
14
votes
2 answers

How can I define pre/post-increment behavior in Perl objects?

Date::Simple objects display this behavior, where $date++ returns the next day's date. Date::Simple objects are immutable. After assigning $date1 to $date2, no change to $date1 can affect $date2. This means, for example, that there is nothing like…
Zaid
  • 36,680
  • 16
  • 86
  • 155
13
votes
2 answers

Why does Knuth use this clunky decrement?

I'm looking at some of Prof. Don Knuth's code, written in CWEB that is converted to C. A specific example is dlx1.w, available from Knuth's website At one stage, the .len value of a struct nd[cc] is decremented, and it is done in a clunky way: …
Ed Wynn
  • 295
  • 1
  • 8
1
2 3
28 29