Well it looks like you just want:

for(int i = 10; i >= 0; i--){
    System.out.println(i);
    System.out.println(10 - i);
} 

Is that the case? Personally I'd normally write this as an increasing loop, as I find it easier to think about that:

for (int i = 0; i <= 10; i++) {
    System.out.println(10 - i);
    System.out.println(i);
} 

Note that your string example is really inefficient, by the way - far more so than introducing an extra variable. Given that you know the lengths involved to start with, you can just start with two char[] of the right size, and populate the right index each time. Then create a string from each afterwards. Again, I'd do this with an increasing loop:

char[] forwardChars = new char[str.length()];
char[] reverseChars = new char[str.length()];
for (int i = 0; i < str.length(); i++) {
    forwardChars[i] = str.charAt(i);
    reverseChars[reverseChars.length - i - 1] = str.charAt(i);
}
String forwardString = new String(forwardChars);
String reverseString = new String(reverseChars);

(Of course forwardString will just be equal to str in this case anyway...)

Answer from Jon Skeet 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

java - Best idiom for a decrementing loop - Stack Overflow
And as an aside, I favor the prefix ... for for-loops, since it will avoid taking an unnecessary copy of idx (though many compilers will probably recognize this and fix it for you). ... for (int idx = len; --idx >= 0; ) is more concise. FWIW, the pre-decrement form --idx >= 0 requires fewer Java byte codes ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
java - Decrement on While loops - Stack Overflow
Sign up to request clarification or add additional context in comments. ... It means that the while loop start looping from 9(backwards) and decrementing? also the while is squaring(power of two) not doubling. Thanks for aswering. More on stackoverflow.com
๐ŸŒ stackoverflow.com
Can someone explain increment and decrement operator in a while loop?
so your while loop will continue to run over and over again until the condition specified is no longer met (the condition that num is less than or equal to times). When your loop first started the condition was met but the variable num never changed which meant that the conditon was always met leading to that infinite loop. To stop the loop you need some way to no longer meet the condition which is where the ++ comes in. num++ is the same as num = num + 1 so every time you repeat the loop you are changing num's value by 1 until finally num is too big to meet the condition and the loop no longer runs as a result. More on reddit.com
๐ŸŒ r/learnjava
2
4
January 15, 2020
How to Decrement a loop in Java - Stack Overflow
Learn more about Collectives ... Bring the best of human thought and AI automation together at your work. Explore Stack Internal ... I am trying to print the output of numbers from 50 to 40 by decrementing the numbers to 1 and to 2. I've tried using for loop and do while loop to decrement the ... More on stackoverflow.com
๐ŸŒ stackoverflow.com
๐ŸŒ
Codefinity
codefinity.com โ€บ courses โ€บ v2 โ€บ 8204075c-f832-4cb9-88b1-4e24e74ebdcb โ€บ 3e046a04-a59c-4fc2-95d5-5d34cff8249b โ€บ d5d1873b-9640-4d8b-94de-d61ed41c8651
Learn Increment and Decrement | Loops
1234567891011121314 package ... output the numbers from 0 to 4. In the second for loop, the variable j is initialized to 5, decremented by 1 after each iteration, and the loop executes until j is no longer greater than 0. ...
๐ŸŒ
Coderanch
coderanch.com โ€บ t โ€บ 753379 โ€บ java โ€บ Decrement-numbers-loop
Decrement of numbers using while loop (Beginning Java forum at Coderanch)
August 2, 2022 - Well, after n has decremented, ... we're decrementng n and not incrementing it), so the loop is run again, but this time with n = -1. This continues running for n = -1, n = -2, n = -3, etc. All the time, the sum will become more and more negative, because you're adding negative numbers with an increasing magnitude to it. Java's primitive ...
๐ŸŒ
Quora
quora.com โ€บ How-can-we-use-the-loop-in-Java-to-decrement-the-string
How can we use the loop in Java to decrement the string? - Quora
Example โ€” decrement a lowercase alphabetic counter ("a".. "z"), with wrap/borrow: ... Use for/while loop to repeatedly modify and print or collect states.
๐ŸŒ
Cprogramming
cboard.cprogramming.com โ€บ c-programming โ€บ 7564-increment-decrement-loop.html
Increment/Decrement for loop?
December 22, 2001 - About the code I posted prior to your post,it does exactly the same..print the pyramid,however it requires minor changes... for(j = 1;j<=5-i;j++) ==> I can't figure out why this is required at all,the loop before this for(i = 1;i<=5;i++) runs till _i = 5_ and the next loop for(j = 1;j<=i;j++) again depends on the first loop...my problem there is no condition check...how does it work...I'm working on it but just can't figure out how to make the damn thing work...
๐ŸŒ
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.
Find elsewhere
๐ŸŒ
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.
๐ŸŒ
Reddit
reddit.com โ€บ r/learnjava โ€บ can someone explain increment and decrement operator in a while loop?
r/learnjava on Reddit: Can someone explain increment and decrement operator in a while loop?
January 15, 2020 -

I've been doing the MOOC Introduction to OOP course part 1 for a while, and I've been having a blast. I'm used to python, and no other language has got my attention like this, for some reason.

There is a thing, I don't quite understand. The increment operator in it self, raises the value of your variable by 1. However, in several excercises now, we have been doing something similar to this:

import java.util.Scanner;

public class ManyPrints {
    // NOTE: do not change the method definition, e.g. add parameters to method
    public static void printText() {
        System.out.println("In the beginning there were the swamp, the hoe and Java");
        // Write your code here
    }

    public static void main(String[] args) {
        // ask the user how many times the text should be printed
        // use the while structure to call the printText method several times
        Scanner reader = new Scanner(System.in);
        int num = 0;
        System.out.println("How many? ");
        int times = Integer.parseInt(reader.nextLine());
        
        
        while(num <= times) {
            printText();
            num++;
        }
    }
}

On the first try, I didn't even have the increment operator in my code, and it would just constantly print my code. Then I thought of this, because we have been doing it a lot, and it worked. However, I don't understand why. Why does the increment operator, make the program able to stop after the number in the user input? Why doesn't it just keep increasing the value by 1?
Sure while num is less or equal to times that part of the code runs, but if i remove the increment operator, it would be infinite.

Thank you.

๐ŸŒ
TutorialsPoint
tutorialspoint.com โ€บ what-are-the-restrictions-on-increment-and-decrement-operators-in-java
What are the restrictions on increment and decrement operators in java?
July 30, 2019 - The increment operator increments the value of the operand by 1 and the decrement operator decrements the value of the operand by 1. We use these operators to increment or, decrement the values of the loop after executing the statements on a value. ... public class ForLoopExample { public static ...
๐ŸŒ
Tutorial Gateway
tutorialgateway.org โ€บ java-for-loop
Java For loop
March 25, 2025 - If the condition is False, then it will exit. After completing the iteration, it will execute the Increment and Decrement Operator inside the for loop to increment or decrement the value.
๐ŸŒ
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.
๐ŸŒ
Trinket
books.trinket.io โ€บ thinkjava2 โ€บ chapter6.html
Loops and Strings | Think Java | Trinket
If you want to increment or decrement a variable by an amount other than 1, you can use += and -=. For example, i += 2 increments i by 2: ... The loops we have written so far have three parts in common.