-6

What does the ++ sign mean in this code:

for (var i=0; i < myString.length; i++) {
    alert(myString[i]);
}

while (x>y) {
    alert ("xrules!");
    y++;
}
chepner
  • 497,756
  • 71
  • 530
  • 681
lisa turner
  • 31
  • 1
  • 5

2 Answers2

0

It's the increment operator. It's (almost) equivalent to saying i = i + 1

Note that the increment operator does not exist in python, you have to either write the whole thing out or use the add assignment operator i += 1

Note that there are post (i++) and pre (++i) increment operators, as well as equivalent decrement operators --i i--. These operators differ on when the increment is applied, and are often a cause of frustration for new programmers.

Community
  • 1
  • 1
ktbiz
  • 586
  • 4
  • 13
  • thanks ktbiz. so if the increment or decrement operator is before i does it mean the same thing? – lisa turner Jan 16 '16 at 02:23
  • Not quite, hence the frustation. Here's a [discussion](http://stackoverflow.com/questions/4706199/post-increment-and-pre-increment-within-a-for-loop-produce-same-output) of the differences between the pre and post increment operators. The same applies for the decrement. – ktbiz Jan 16 '16 at 02:26
0

++ is the increment operator

saying

y++

is the same thing as saying

y = y + 1
Dustin Nunyo
  • 96
  • 1
  • 9