I think you mean > instead of <:

for (int i = 10; i > 0; --i) {

If you want the values of i to be the same as in the original code except in reverse order (i.e. 9, 8, 7, ..., 1, 0) then you also need to change the boundaries:

for (int i = 9; i >= 0; --i) {
Answer from Mark Byers on Stack Overflow
🌐
Quora
quora.com › How-we-can-use-loop-in-C-to-decrement-the-number-from-10-to-1
How we can use loop in C to decrement the number from 10 to 1? - Quora
Answer (1 of 48): use decrement function that is(- -) use this : for(i=10;i>0;i- -) { printf(“%d”,i); }
Discussions

Decrementing Initialization of a For Loop (C) - EX: for(i--; i>0; i--) - Stack Overflow
I have been reading about operating system design in the book, "The Xinu Approach 2nd Ed.", and came across a for loop statement in chapter 10 on page 182/183. The for loop starts off decrementing the initialization statement of the for loop. More on stackoverflow.com
🌐 stackoverflow.com
decrement size_t in loop - C++ Forum
Hi everyone, I was recommended ... warnings for debugging purposes. The compiler frequently complained that I was comparing signed and unsigned integers in my loop heads. Thinking it to be better practice to turn all loop counters to size_t, I ran into a problem with a loop that is supposed to decrement to 0 and exit ... More on cplusplus.com
🌐 cplusplus.com
June 9, 2022
c - Which loop has better performance? Increment or decrement? - Stack Overflow
But it's a micro-optimisation, and you should profile to see whether it's really worth doing. The compiler will often make the optimisation for you, and given that the decrement loop is arguably a worse expression of intent, you're often better off just sticking with the 'normal' approach. More on stackoverflow.com
🌐 stackoverflow.com
For loop in C, with automatic increment or decrement depending on init and end conditions - Stack Overflow
I recall seeing a very elegant "for" loop construct in C, that would increment or decrement the loop variable automatically based on whether the initial value was more or less than the end condition More on stackoverflow.com
🌐 stackoverflow.com
November 6, 2012
🌐
Tutorial Gateway
tutorialgateway.org › for-loop-in-c-programming
For Loop in C Programming
February 7, 2026 - Step 1 (Initialization): We initialize the counter variable(s). It is an entry to the for loop. Example, i=1. Step 2 (Expression): It will check the condition against the counter variable. Step 3: If the condition is True, the compiler moves to the group of statements section and executes the statements inside it. Step 4 (Update): After completing the iteration Step 3 (from the group of statements section), it will execute the Increment and Decrement Operators inside it to increment or decrease the value.
🌐
YouTube
youtube.com › timothy unkert
C Programming Tutorial - Decrementing For Loop - YouTube
In this #C #Programming #Tutorial I discuss a #decrementing #for #loop.Source code:https://github.com/Tunkert/programming-in-c-on-a-chromebook-in-2022My soci...
Published   January 2, 2022
Views   346
🌐
Cprogramming
cboard.cprogramming.com › c-programming › 7564-increment-decrement-loop.html
Increment/Decrement for loop?
December 22, 2001 - tcnt and scnt have to do with the order and number of tabs. tcnt means tab count and is the variable actually used in the loop, scnt means static count and is used to set the decreasing amount of tabs starting at 3 and going down as the lines get longer. The infinite loop has been taken care ...
🌐
BeginnersBook
beginnersbook.com › 2014 › 01 › c-for-loop
C – for loop in C programming with example
4) This is also possible. The counter variable is initialized before the loop and incremented inside the loop. int num=10; for (;num<20;) { //Statements num++; } 5) As mentioned above, the counter variable can be decremented as well.
🌐
Txstate
userweb.cs.txstate.edu › ~js236 › 201112 › cs1428 › lecture13.pdf pdf
Ch 5. Looping Increment and Decrement
Ch 5. Looping · Part 2 · CS 1428 · Fall 2011 · Jill Seaman · Lecture 13 · 2 · Increment and Decrement · Loops commonly have a counter variable · Inside the loop body, counter variable is often · − · incremented: increased by one OR · − · decremented: decreased by one ·
Find elsewhere
🌐
Newtum
blog.newtum.com › while-loop-decrement-in-c
While Loop Decrement in C - Newtum
July 29, 2024 - This is called “initialization.” Next, we have given the condition and after that, we have given the decrement. Now, the only thing is the printf statement. Instead of printf, we can write any logic that we want, So What we understand is for Loop execution.
🌐
Unstop
unstop.com › home › blog › for loop in c explained with detailed code examples
For Loop In C Explained With Detailed Code Examples
January 12, 2024 - The decrement for loop is similar to the simple increment loop but starts with a higher initial value and decrements i by 1 after each iteration until the condition (i > end) becomes false.
🌐
Programtopia
programtopia.net › home › c programming › for loop in c programming
for loop in C Programming - Programtopia
January 15, 2021 - If this part is left blank, it is considered true in C causing the loop to run infinite times. ... In these examples, i<=10 and i <strlen(name) are conditions. This part increments or decrements the value of a variable that is being checked. This part is executed at the end of each iteration before executing the conditional part.
🌐
GeeksforGeeks
geeksforgeeks.org › c language › increment-and-decrement-operators-in-c
Increment and Decrement Operators in C - GeeksforGeeks
May 21, 2025 - The increment ( ++ ) and decrement ( -- ) operators in C are unary operators for incrementing and decrementing the numeric values by 1, respectively. They are one of the most frequently used operators in programming for looping, array traversal, ...
🌐
Cplusplus
cplusplus.com › forum › beginner › 283889
decrement size_t in loop - C++ Forum
June 9, 2022 - As size_t will never become -1 (instead it seems to become the largest possible value), this will turn into an infinite loop. Fortunately, the compiler warned me about this as well. How can I write the following correctly? for (size_t i = my_vector.size() - 1; i >=0; i -= my_decrement) Best, PiF
🌐
TutorialsPoint
tutorialspoint.com › cprogramming › c_for_loop.htm
For Loop in C
In this case, the initial value of the looping variable is more than its value in the test condition. The last clause in the for statement uses decrement operator.
🌐
WsCube Tech
wscubetech.com › resources › c-programming › increment-decrement-operators
Increment and Decrement Operators in C (With Examples)
March 3, 2026 - Learn in this tutorial about C increment and decrement operators, including pre-increment, post-increment, pre-decrement, and more, with examples. Read now!
Top answer
1 of 4
2

You can use any expression:

int n = 10;
while (n > 0)   // Note change compared with original!
{
    // Do something
    n = round(n/3.0) - 1;  // Note assignment and floating point
}

Note that you can only decrement variables, not expressions.

You could also use a for loop:

for (int n = 10; n > 0; n = round(n/3.0) - 1)
{
    // Do something
}

In this case, the sequence of values for n will be the same (n = 10, 2) whether you round using floating point or not, so you could write:

n = n / 3 - 1;

and you'd see the same results. For other upper limits, the sequence would change (n = 11, 3). Both techniques are fine, but you need to be sure you know what you want, that's all.

2 of 4
2

Yes, it is possible to add or subtract any number to your variable n.

Usually, if you want to do something a very predictable number of times, you would use a for loop; when you aren't sure how many times something will happen, but rather you are testing some sort of condition, you use a while loop.

The rarest loop is a do / while loop, which is only used when you want to execute a loop one time for certain before the first time the while check occurs.

Examples:

// do something ten times
for (i = 0; i < 10; ++i)
    do_something();

// do something as long as user holds down button
while (button_is_pressed())
    do_something();

// play a game, then find out if user wants to play again
do
{
    char answer;
    play_game();
    printf("Do you want to play again?  Answer 'y' to play again, anything else to exit. ");
    answer = getchar();
} while (answer == 'y' || answer == 'Y');
🌐
Tutorial Gateway
tutorialgateway.org › while-loop-in-c
While Loop in C Programming
March 23, 2025 - At the beginning, the While loop checks for the condition. If the condition is True, then it will execute the statements inside of it. Next, we have to use the Increment & Decrement Operator inside it to increment and decrement the value.