• Register
0 votes
152 views

Problem:
When I compile and run the code below with either count++ or ++count substituted for the variable X, the output is identical; in both cases.

for (int count = 1; count < 11; x)
{
    std::cout << count << endl;
}

Can you please explain the order in which the three actions are evaluated in the for loop header, and explain exactly where the iterations occur when using count++ and ++count?

830 points

Please log in or register to answer this question.

1 Answer

1 vote

Solution:

All we need to know is: Increment operators are used to increasing the value by one while decrement works opposite increment.

Pre-increment (++i) − Before assigning the value to the variable, the value is incremented by one.

Post-increment (i++) − After assigning the value to the variable, the value is incremented.

we declare loop in our codes like below:

 

for (initialization; condition; increment/decrement)
    code;

But iteration follows the steps as given below:

{
    initialization;
    while (condition)
    {
        code;
        increment/decrement;
    }
}

 

1.5k points

Related questions

0 votes
1 answer 16 views
16 views
Problem: When I compile and run the code below with either counter++ or ++counter substituted for x, the output is identical; in both cases it says: You can either increment or decrement the loop control variable. Could you please precisely explain how to avoid it?
asked Apr 22 anika11 32.2k points
0 votes
1 answer 22 views
22 views
Problem: What i have to do if my computer show this control? Can anyone help me out?
asked Mar 20 niyatiry 3.9k points
0 votes
1 answer 52 views
52 views
I want to develop an increment statement and decremnet statement . Is there anyone here that can give me a hint on how to start ?
asked Sep 25, 2020 okeke 360 points
0 votes
1 answer 12 views
12 views
Problem: Is there anyone who knows the answer : Only assignment, call, increment, decrement, and new object expressions can be used as a statement?
asked Jun 10 Mezbah 125k points
0 votes
1 answer 7 views
7 views
Problem: Questions on increment and decrement operators in c
asked Jun 27 Sawyer Parviz 166k points
0 votes
1 answer 4 views
4 views
Problem : C# only assignment call increment decrement.
asked Jul 11 Isac Christiaan 102k points
0 votes
1 answer 46 views
46 views
Problem: Please help me &hellip; how can I solve it?
asked Mar 12 Ifra 43.4k points
0 votes
2 answers 808 views
808 views
Problem: A ________ value in a loop can be either a positive or a negative number. Is this true of False? I am bit confused can anyone suggest?
asked Sep 29, 2019 anonymous
0 votes
0 answers 9 views
9 views
Problem: >HELP! I need help understanding this problem? in a for loop, the control variable can only be incremented.
asked Apr 10 Rohit kr 17.5k points
0 votes
1 answer 84 views
84 views
Explain with an example?
asked Oct 8, 2020 jagruthi 680 points