How it+ differs from ++i

Слайд 2

Often a novice programmer gets lost in these i ++ and ++

Often a novice programmer gets lost in these i ++ and ++
i. In this short post, we will try to clarify the material so that there is no doubt that you will never get confused and will definitely correctly decide which option should be used in a particular case. Perhaps you need to start with a definition. The ++ operator is shorthand for increment. In other words, this operator is used to add 1 to a variable.

Слайд 3

But why, and most importantly, in what cases i ++! = ++

But why, and most importantly, in what cases i ++! = ++
i? The fact is that the increment operation, like other operations, returns the result of the same operation. What is important is the result! Having understood this, there will be no more questions.

Слайд 4

I++ increment operation

This operation returns the value of I before 1 is

I++ increment operation This operation returns the value of I before 1
added to I.

Increment operation ++ I This operation returns I after the addition operation I + 1

Слайд 5

Now to consolidate the material, I will give a few examples.

Now to consolidate the material, I will give a few examples.

Слайд 6

Example 1: while loop

As we can see in the first case i

Example 1: while loop As we can see in the first case
value is displayed after the addition operation and in the second case: before.

Слайд 7

Example 2: for loop

In this case, in fact, nothing changes. Those. whether

Example 2: for loop In this case, in fact, nothing changes. Those.
you use ++ i or i ++, in the body of the loop we get i = i + 1. Therefore, you should not rack your brains over this at all. It all depends on the preferences of the programmer and does not affect the course of the program in any way.

Слайд 8

The following example is identical to example 1 with a while loop:

The following example is identical to example 1 with a while loop:
Имя файла: How-it+-differs-from-++i.pptx
Количество просмотров: 40
Количество скачиваний: 0