what is this i++ and i--? | Codecademy (2024)

Skip to ContentMini Arrow Down Icon

This forum is now read-only. Please use our new forums! Go to forums

points

what is this i++ and i--? | Codecademy (1)

Submitted by eggwithnofear

almost 11 years

i finished the whole exercise 7 by fluke i mean i didnt get a single bit of what i did and why i did them.infact i couldn’t understand what the questions were what are these i=2 or i++ or i– or tehse { ] used for or what is that FOR loop..i didnt seem to get any of it (maybe because English is not my first language) or im just stupid :p if anyone is free right now could you explain it to me??

Answer 4f1d4841d9bb18000100c688

1

vote

Permalink

i++ increment the variable i by 1. It is the equivalent to i = i + 1.

i– decrements (decreases) the variable i by 1. It is the equivalent to i = i - 1.

points

what is this i++ and i--? | Codecademy (2)

Submitted by JoeFletch

almost 11 years

Answer 4f2064f3d97f670001002bd0

3

votes

Permalink

The FOR loop is what is known as a control structure. Control structures allow the programmer to make decisions in their programs based on changing values like a number supplied by the user for instance.

The purpose of the FOR loop is to repeat a task x number of times where x is some dynamic value. Each time we perform the task is considered one iteration or loop through the FOR loop.

In most instances of FOR loop usage I would need at least 2 separate values: I need a counter value and a limit (condition) value.

The counter value in the case of this problem would be the variable i that was declared at the top:

var i; <—- counter value

And the limit or condition value would be the number 2:

2 <—- limit value

In the case of this particular problem you are required to use a constant or unchangeable value ( 2 ) as the limit/condition value. You could and most of the time would use another variable value like i for the limit/condition value.

The counter value is the value we use to determine how many times we have performed the task and the limit or condition value is the value we use to determine if we’ve performed the task the amount of times we need to.

Now every time my FOR loop goes to do what I’ve assigned it to do I the programmer need to do 3 things:

  1. Compare the counter value to the limit value - if my counter value equals my limit value I’m done and the FOR loop has completed it’s task. If the values are not equal then I need to continue performing the task until they are equal.
  1. Perform the task assigned to the FOR loop - print a message for instance.
  1. Update my counter value to reflect that we just made it through another loop.

Tasks 1 and 3 are handled in the FOR loop declaration:

for (i = 0; i < 2; i++)

This statement is broken up into 3 sections: initialization; condition; increment.

In the initialization section ( i = 0 ) we initialize our counter value i to the number 0.

In the condition section ( i < 2 ) we test to see if our counter value ( i ) is equal to our limit/condition value ( 2 ).

And in the increment section ( i++ ) we increase the value of our counter value every time we complete a loop of the FOR loop.

The ++ symbol we use in the increment section is called the increment operator - it works just like any counter you can think of in real life. When I call it it simply adds 1 to whatever variable I call it on. In this case the variable is i. If i equals 0 before I call i++, i will be equal to 1 after I call it.

Another similar symbol is the – symbol. You probably guess that it decreases the value of a variable by 1 every time it is called and is therefore called the decrement operator. If i = 0 and I call i–, i will then equal -1 after I call it.

Each section of the FOR loop declaration statement must be separated by the semicolon: for(section; section; section).

Now since a FOR loop structure can contain any number of statements that we may wish for it to execute on each loop through the structure we need to specify in our program which lines or statements of code we intend to be included in the FOR loop structure. This is where the brackets {} come into play.

Example:

for(i = 0; i < 2; i++)

{

do something;

do something;

do something;

etc…

}

Since each do something line is a complete statement (as noted by the semicolon at the end of the statement), the interpreter that will interpret what my program wants to do would have no way of knowing which of those lines I wished for it to consider as part of the FOR loop if I were to omit the {} brackets.

points

what is this i++ and i--? | Codecademy (3)

Submitted by meddle

almost 11 years

Answer 4f1e04741dc70f0001002147

2

votes

Permalink

Just add a line between the two lines printed and say i = i + 2 or i = i - 2.

points

what is this i++ and i--? | Codecademy (4)

Submitted by Mark Nifakos

almost 11 years

Answer 4f2066fcc31da4000100342a

votes

Permalink

Well that got a bit garbled lol.

Line 15 ( var i; < 2; i++)) should have looked like this instead:

var i;

And the limit or condition value would be the number 2:

2

points

what is this i++ and i--? | Codecademy (5)

Submitted by meddle

almost 11 years

what is this i++ and i--? | Codecademy (2024)

FAQs

What is i ++ meaning? ›

i++ increment the variable i by 1. It is the equivalent to i = i + 1. i– decrements (decreases) the variable i by 1.

What is ++ i vs i ++? ›

In the prefix version (i.e., ++i), the value of i is incremented, and the value of the expression is the new value of i. So basically it first increments then assigns a value to the expression. In the postfix version (i.e., i++), the value of i is incremented, but the value of the expression is the original value of i.

Is i ++ the same as i += 1? ›

These two are exactly the same. It's just two different ways of writing the same thing. i++ is just a shortcut for i += 1 , which itself is a shortcut for i = i + 1 .

What is i ++ in for loop? ›

Post-Increment (i++)

In psuedocode, the post-increment operator looks roughly as follows for a variable i : int j = i; i = i + 1; return j; Since the post-increment operator has to return the original value of i , and not the incremented value i + 1 , it has to store the old version of i .

Does i stand for math? ›

Definition and meaning of the math word i. i. The letter i is used to signify that a number is an imaginary number. It stand for the square root of negative one. In electrical engineering it is often replaced by the letter j to avoid conflict with the symbol for current.

What's i stand for? ›

“Steve Jobs said the 'I' stands for 'internet, individual, instruct, inform, [and] inspire,'” Paul Bischoff, a privacy advocate at Comparitech, explains.

What is i ++ in Python? ›

Python does not have unary increment/decrement operator( ++/--). Instead to increament a value, use a += 1. to decrement a value, use− a -= 1.

Does ++ i or i ++ matter in for loop? ›

This means that there is sequence point in for loop after every expression. So, it doesn't matter whether you do ++i or i++ or i+=1 or i=i+1 in the 3rd expression of for loop.

What is the meaning of i += 1? ›

The solution means to say that there is no difference, ++i has the same meaning as (i += 1) no matter what i happens to be and no matter the context of the expression.

What does i += 2 mean? ›

Using += in loops

You can use += in for loop when you want to increment value of variable by more than 1. In general, you might have used i++ , but if you want to increment it by 2, then you can use i+=2 .

Which is better i i 1 or i ++? ›

i=i+1 will have to load the value of i , add one to it, and then store the result back to i . In contrast, ++i may simply increment the value using a single assembly instruction, so in theory it could be more efficient.

What is ++ and += in Java? ›

scoreTeamB++ returns the previous value of the variable (before it was incremented). += returns the value that was assigned to the variable.

What are the 3 types of loops? ›

Loops are control structures used to repeat a given section of code a certain number of times or until a particular condition is met. Visual Basic has three main types of loops: for.. next loops, do loops and while loops.

Why are loops called I? ›

Generally the i in for loops stands for iterator, that's why most of programmers use i instead of other names. i and j are just a variable name, you can use any variable name like a, b, c,x, y or number, length etc.

Can we write I 2 in for loop? ›

We can write a for loop and start the loop from 2 by using i=2 in initialization part and increment the loop by 2 in each iteration by using i+=2 .

What is 3i equal to? ›

Remember that a complex number has the form a + bi. You need to figure out what a and b need to be. Since −3i is an imaginary number, it is the imaginary part (bi) of the complex number a + bi. This imaginary number has no real parts, so the value of a is 0.
...
Imaginary Numbers
3i (b = 3)−672i (b = −672)
(b = )(b = )

What is i in a sum? ›

Summation notation involves:

The variable of summation is represented by an index which is placed beneath the summation sign. The index is often represented by i.

What is 2i? ›

2i is an imaginary number because it has the form 'bi' Remember, 'i' is the imaginary unit and is equal to the square root of -1. Even though 'i' is NOT a variable, we can multiply it as if it were. So i • i gives us i2. Squaring √ (-1) cancels out the square root, leaving us with just -1.

What is the I in life? ›

I is for Integrity.

The “I” in “L.I.F.E.” reminds us that each of us should aim at integrity.

What does AF mean on TikTok? ›

The acronym af translates to a swear word, plain and simple.

What is I and A in Lgbtq? ›

What is i += 1 in Python? ›

i = i+1 will increment the value of i, and then return the incremented value. i++ will increment the value of i, but return the original value that i held before being incremented.16-May-2015.

Why i ++ is not in Python? ›

Why doesn't the “++/--” operator work in Python? If you have used programming languages like C you have likely used the ++/ -- operator to increment or decrement a variable. However, if you have tried the same in Python you would receive an Invalid Syntax error. Python does not treat variables the same way as C.

What is if I & 1 in Python? ›

it is binary "and". Eg 7 = 111 111 and 001 = 1 Actually it is a test if a number i is odd. if yes, the result is 1.

What is the difference between -- I and I --? ›

--i decrements i by 1 then gives you the value of i (4). i-- gives you the value of i (5) then decrements it by 1. Both will give you the same result in a for loop.

How do I use an I? ›

Use the pronoun "I" when the person speaking is doing the action, either alone or with someone else. Use the pronoun "me" when the person speaking is receiving the action of the verb in some way, either directly or indirectly.

Should I use an I? ›

Avoiding “I” can lead to awkwardness and vagueness, whereas using it in your writing can improve style and clarity. Using personal experience, when relevant, can add concreteness and even authority to writing that might otherwise be vague and impersonal.

What is the i power? ›

If you are familiar with complex numbers, the “imaginary” number i has the property that the square of i is -1. It is a rather curious fact that i raised to the i-th power is actually a real number! In fact, its value is approximately 0.20788.

What is the value of 1 by i? ›

The imaginary part is defined with the help of i. Basically, “i” is the imaginary part which is also called iota. Value of i is √-1 A negative value inside a square root signifies an imaginary value.
...
Values of i.
DegreeMathematical CalculationValue
i-11/i = i/i2 = i/-1-i
i-21/i2 = 1/-1-1
i-31/ i3 = 1/-ii
6 more rows

What is the meaning of i 0? ›

I/O (input/output), pronounced "eye-oh," describes any operation, program, or device that transfers data to or from a computer.

What is i += 1 in C? ›

i+=i means the i now adds its current value to its self so let's say i equals 10 using this += expression the value of i will now equal 20 because you just added 10 to its self. i+=1 does the same as i=i+1 there both incrementing the current value of i by 1.

What does =+ mean in C? ›

The value of the expression to the right of the operator is added to the value of the variable to the left of the operator, and the result replaces the value of the variable. For example …

Is it += or =+ in Java? ›

=+ does nothing; it's the same as = here. You have just written sum1 = two . sum2 += one on the other hand is essentially the same as sum2 = sum2 + one .

What does i += 1 mean in C++? ›

i += 1 produces i after incrementing (like a preincrement), while i++ produces i before incrementing. Thus, int a = 0, b = 0; cout << (a+=1) << " " << b++ << endl; prints 1 0 .

Why is ++ faster than i ++? ›

For class types like iterators or the previous FAQ's Number class, ++i very well might be faster than i++ since the latter might make a copy of the this object.

Why is i ++ faster than i i 1? ›

i++ is faster because they return value before.

What is i += 2 in Java? ›

Using += in Java Loops

The += operator can also be used with for loop: for(int i=0;i<10;i+=2) { System. out. println(i); } The value of i is incremented by 2 at each iteration.

What does -= mean in C++? ›

-= Subtract AND assignment operator, It subtracts right operand from the left operand and assign the result to left operand. C -= A is equivalent to C = C - A.

What is && called? ›

The logical AND ( && ) (logical conjunction) operator for a set of boolean operands will be true if and only if all the operands are true .

What are 2 types of loops? ›

Two major types of loops are FOR LOOPS and WHILE LOOPS. A For loop will run a preset number of times whereas a While loop will run a variable number of times. For loops are used when you know how many times you want to run an algorithm before stopping.

Why are loops used? ›

Without the loop structure in a computer program, the tasks are almost impossible to be performed. Loops, on the one hand, execute the tasks faster saving the time and energy, on the other hand, they are very helpful to accomplish the tasks in an accurate manner.

What is i for loop used for? ›

print (i); } The above For Loop will print the natural numbers 1 to 10 when executed. The variable 'i' is of integer type, and the condition will check if the value of 'i' is less than 10, at each iteration. After executing the body of the Loop, the value of 'i' is incremented by 1, before the next iteration.

Why is I used in C? ›

In C programming language, %d and %i are format specifiers as where %d specifies the type of variable as decimal and %i specifies the type as integer. In usage terms, there is no difference in printf() function output while printing a number using %d or %i but using scanf the difference occurs.

What does I mean in a loop? ›

If someone is in the loop, they are part of a group of people who make decisions about important things, or they know about these decisions. If they are out of the loop, they do not make or know about important decisions. [mainly US, informal]

Can I use two I in a sentence? ›

Yes, that is appropriate. One use of “I” in a sentence is fine, and two or more uses are fine too, and of course multiple uses may be required by the information the sentence is intended to convey.

What is the difference between i i 1 and i += 1 in a for loop? ›

The difference is that one modifies the data-structure itself (in-place operation) b += 1 while the other just reassigns the variable a = a + 1 .

What is loop in C++ with example? ›

C++ Infinite for loop

If the condition in a for loop is always true , it runs forever (until memory is full). For example, // infinite for loop for(int i = 1; i > 0; i++) { // block of code } In the above program, the condition is always true which will then run the code for infinite times.

What type of word is i? ›

pronoun, nominative I,possessive my or mine,objective me;plural nominative we,possessive our or ours,objective us. the nominative singular pronoun, used by a speaker in referring to himself or herself.

What does i or E mean? ›

I.e. and e.g. are both Latin abbreviations. E.g. stands for exempli gratia and means “for example.” I.e. is the abbreviation for id est and means “in other words.” Remember that E is for example (e.g.) and that I and E are the first letters of in essence, an alternative English translation of i.e.

What is the meaning of i and j? ›

The small distinguishing mark you see over a lowercase i and a lowercase j is called a tittle—an interesting name that looks like a portmanteau (combination) of tiny and little, and refers to a small point or stroke in writing and printing.

What are the uses i? ›

"I" is a nominative pronoun, which means that it is used as the subject of a sentence, or as a predicate nominative. For example: I went to the store.

What type of word is it? ›

pronoun, nominative it,possessive its or (Obsolete or Dialect) it,objective it;plural nominative they,possessive their or theirs,objective them.

What type of word is is? ›

Is is what is known as a state of being verb. State of being verbs do not express any specific activity or action but instead describe existence. The most common state of being verb is to be, along with its conjugations (is, am, are, was, were, being, been).

What is a 3 letter i word? ›

The 3 Letter Words Starting With I are ink, irk, ivy, ifs, ick, ion, ice, ire, icy, ill, imp, inn, its, etc. These are some of the 3 Letter Words Starting With I for kids.

Are e and i vowels? ›

The long e, short i, and short e /i, ɪ, ɛ/, are three front vowel sounds that can be practiced from a high, front tongue position to a mid-front position.

Is it an i or AI? ›

There's no hard and fast rule - English spelling is a complicated mess - but by and large if the "i" is followed by a single consonant and a vowel it's pronounced as long /ai/, and if followed by two consonants, or a single consonant at the end of the word, it is pronounced as short /i/.

Is E and i the same? ›

The difference in pronunciation is the degree to which the jaw is opened; [e] is less open than [i]. The position of the tongue is the same for both vowels (this is in the front).

What is the i and j in vectors? ›

The unit vector i has a magnitude of 1 and its direction is along the positive x-axis of the rectangular coordinate system. The unit vector j has a magnitude of 1 and its direction is along the positive y-axis of the rectangular coordinate system.

How do you write the vector i and j? ›

A vector can be described using i,j notation. A unit vector is a vector of length 1, in Cartesian co-ordinates the unit vectors along the axis are denoted by i and j respectively. Any two-dimensional vector can be written in the form ai+bj a i + b j .

What's the dot over i and j called? ›

So why is there a dot above the lowercase i and j? This diacritical mark is also called a tittle and it exists to help the reader easily distinguish them from other letterforms.

What is the form of I? ›

In Modern English, I is the singular, first-person pronoun.

What is using i called? ›

"I" and "me" are first-person personal pronouns that we use to refer to ourselves. A personal pronoun is a word used as a substitute for someone's name.

Top Articles
Latest Posts
Article information

Author: Jamar Nader

Last Updated:

Views: 6455

Rating: 4.4 / 5 (55 voted)

Reviews: 86% of readers found this page helpful

Author information

Name: Jamar Nader

Birthday: 1995-02-28

Address: Apt. 536 6162 Reichel Greens, Port Zackaryside, CT 22682-9804

Phone: +9958384818317

Job: IT Representative

Hobby: Scrapbooking, Hiking, Hunting, Kite flying, Blacksmithing, Video gaming, Foraging

Introduction: My name is Jamar Nader, I am a fine, shiny, colorful, bright, nice, perfect, curious person who loves writing and wants to share my knowledge and understanding with you.