Simply increase your step size!

for stepSize in range(10):
    for count in range(10):
        print((count + 1) * (stepSize + 1), end=" ")
    # count loop has ended, back into the scope of stepSize loop
    # We are also printing(" ") to end the line
    print(" ")
# stepSize loop has finished, code is done

Explanation: The first, outer loop is increasing our step size, then for each step size we count up 10 steps and finish the line when we print(" ") in the outer for loop.

Answer from Capn Jack on Stack Overflow
🌐
Du
cs.du.edu › ~intropython › intro-to-programming › nested_for_loops.html
Nested for-loops - Introduction to Programming
We return to the outer for-loop, and update the value of row to 1. Then the inner block is repeated, with column taking the values 0, 1, 2, then 3. For each new value of column, a * is output, resulting in ****. Again a newline from the print() statement takes us to the next line, followed by a return to the outer for-loop, where row is updated to its final value of 2. The entire inner for loop is executed again, producing a third line **** of output.
🌐
Studocu
studocu.com › university of victoria › fundamentals of programming i › question
[Solved] What nested for loops produce the following output 1 2 3 4 5 - Fundamentals of Programming I (Csc110) - Studocu
November 30, 2022 - public class Main { public static void main(String[] args) { int n = 5; // set n to 5 // nested loops to print the pattern for(int i = 0; i<n;i++) // loop for lines and number { for(int j = n-1; j>i; j--) // loop to print .
🌐
JustAnswer
justanswer.com › computer-programming › 6n15x-write-nested-loop-produce-following-output.html
Write a nested loop to produce the following output: 1 2 3 4 5 2 3 4 5 3 4 5 4 5 5
In Java Only: Write a "for" loop to produce following output. 10 9 8 7 6 5 4 3 2 1 0 ... I am using java language. write a program fragment using nested loops to generate the following output: * *** *****
🌐
PYnative
pynative.com › home › python › nested loops in python
Python Nested Loops [With Examples] – PYnative
September 2, 2021 - In the following example, we have two loops. The outer for loop iterates the first list, and the inner loop also iterates the second list of numbers. If the outer number and the inner loop’s current number are the same, then move to the next iteration of an inner loop. ... first = [2, 4, 6] second = [2, 4, 6] for i in first: for j in second: if i == j: continue print(i, '*', j, '= ', i * j)Code language: Python (python) Run
🌐
University of Washington
courses.cs.washington.edu › courses › cse142 › 17wi › lectures › 01-11 › slides › 04-nested-loops-constants.pdf pdf
1 Building Java Programs Chapter 2 Nested Loops, Figures and Constants
..3 · .4 · 5 · 19 · Nested for loop exercise · ! What is the output of the following nested for loops? for (int line = 1; line <= 5; line++) { for (int j = 1; j <= (-1 * line + 5); j++) { System.out.print("."); } for (int k = 1; k <= line; k++) { System.out.print(line); } System.out.println(); } ! Answer: ....1 · ...22 · ..333 · .4444 · 55555 · 20 · Nested for loop exercise · ! Modify the previous code to produce this output: ....1 ·
Top answer
1 of 8
20
for (int i = 1; i <= 4; i++){
    for (int j = 1; j <= 12; j++){
        System.out.print("~");
    }
}
System.out.println();

can easily be:

for (int i = 0; i < 48; i++) {
    System.out.print('~');
}
System.out.println();

Some edits:

  • Improved formatting: ){ to ) {
  • Simplified to one for loop that runs from 0 to 47 (start at 0, run to less than 48)
  • Print a single char instead of a String with one char in it to improve performance

This:

        System.out.print("~");

for (int i = 1; i <=15; i++){
        System.out.print("+~~");
}
        System.out.println("+~");

Can be this:

for (int i = 0; i < 16; i++){
    System.out.print("~+~");
}
System.out.println();

What changed:

  • Better formatting
  • Loops and prints the ~+~ pattern
        System.out.print("+~");
for (int i = 1; i <= 15; i++){
        System.out.print("++~");
    }
        System.out.println("+");

to:

for (int i = 0; i < 16; i++){
    System.out.print("+~+");
}
System.out.println();

Changes made:

  • Better formatting
  • Loops and prints the +~+ pattern

All of the fixes have some things in common:

  • Indentation and formatting
  • Find the correct pattern

Other changes:

  • Use methods:

    Currently all your code is in the main method. Split it up.

Final code:

public class Exercises {

    public static void main (String[] args){
        printTildes();
        printTPT_Pattern();
        printPTP_Pattern();
        printTildes();
    }

    private static void printTildes() {
        for (int i = 0; i < 48; i++){
            System.out.print("~");
        }
        System.out.println();
    }

    private static void printTPT_Pattern() {
        for (int i = 0; i < 16; i++){
            System.out.print("~+~");
        }
        System.out.println();
    }

    private static void printPTP_Pattern() {
        for (int i = 0; i < 16; i++){
            System.out.print("+~+");
        }
        System.out.println();
    }

}
2 of 8
41

You're not breaking up the patterns in the most logical way. Each line just consists of repeating blocks of three characters.

public class SquigglePlus {
    private static final String[] PATTERNS = { "~~~", "~+~", "+~+", "~~~" };

    public static void main(String[] args) {
        for (int line = 0; line < PATTERNS.length; line++) {
            for (int col = 0; col < 48; col += PATTERNS[line].length()) {
                System.out.print(PATTERNS[line]);
            }
            System.out.println();
        }
    }
}

Alternatively, the inner loop could just count to 16: for (int i = 0; i < 16; i++) { … }. Note that in Java, that is the most idiomatic way to count: start with 0, and use < for the termination check. The other way (for (int i = 1; i <= 16; i++) { … }) would not be wrong, but usually you would write it that way only if you had a special reason.

Better yet, use a modern enhanced for-loop instead of the old-style counting loop.

public class SquigglePlus {
    private static final String[] PATTERNS = { "~~~", "~+~", "+~+", "~~~" };

    public static void main(String[] args) {
        for (String pattern : PATTERNS) {
            for (int col = 0; col < 48; col += pattern.length()) {
                System.out.print(pattern);
            }
            System.out.println();
        }
    }
}
🌐
Educative
educative.io › answers › printing-patterns-with-numbers-using-nested-for-loops
Printing patterns with numbers using nested for-loops
In the above code, the outer loop iterates from 1 to 5. For each iteration of this loop, an inner loop is used to print the numbers starting from the current value of the outer loop variable to 5. For example, the inner loop starts from 1, in the second row from 2, and so on. In pattern 5, each row starts with 5 and decrements by 1 until it reaches the number dictated by its row number. ... Let's implement this pattern using the nested for loop. ... Line 3: The outer loop handles the number of rows printed in the pattern.
Find elsewhere
🌐
GeeksforGeeks
geeksforgeeks.org › c language › nested-loops-in-c-with-examples
Nested Loops in C - GeeksforGeeks
If the outer loop is running from i = 1 to 5 and the inner loop is running from j = 0 to 3. Then, for each value of the outer loop variable (i), the inner loop will run from j = 0 to 3. Nested for loop refers to any type of loop that is defined ...
Published   November 7, 2025
🌐
University of Texas
cs.utexas.edu › ~scottm › cs305j › handouts › slides › Topic6NestedForLoops_4Up.pdf pdf
Topic 6 Nested for Loops
1 2 3 4 5 6 7 8 9 10 · 2 4 6 8 10 12 14 16 18 20 · 3 6 9 12 15 18 21 24 27 30 · CS305j Introduction to Computing · Nested For Loops · 3 · 4 8 12 16 20 24 28 32 36 40 · 5 10 15 20 25 30 35 40 45 50 · Nested for loop exercise · Wh t i th · t · t · f th · f ll · i · t d · What ...
🌐
Runestone Academy
runestone.academy › ns › books › published › csawesome › Unit4-Iteration › topic-4-4-nested-loops.html
4.4. Nested For Loops — CSAwesome v1
The outer loop runs from 1 up to ... This would be true if the inner loop continued while y < 5. ... for (int i = 0; i < 5; i++) { for (int j = 3; j >= 1; j--) { System.out.print("*"); } System.out.println(); }...
🌐
Brainly
brainly.com › engineering › college › using nested loops, write code to produce the following output. **nb:** use only two loops. ``` 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 ```
[FREE] Using nested loops, write code to produce the following output. NB: Use only two loops. 1 2 3 4 5 6 7 - brainly.com
August 9, 2023 - When you run this code, you will get the required output: 1 2 3 4 5 6 7 8 1 2 3 4 5 6 7 1 2 3 4 5 6 1 2 3 4 5 1 2 3 4 1 2 3 1 2 1 · The example provided shows a Python code snippet that effectively demonstrates the use of nested loops to create ...
🌐
Python.org
discuss.python.org › python help
Python Code for nested loops - Python Help - Discussions on Python.org
August 31, 2022 - Does anyone know how to print the following pattern using nested loops? 1 1 2 1 2 3 1 2 3 4 1 2 3 4 5
🌐
GeeksforGeeks
geeksforgeeks.org › python › python-nested-loops
Python Nested Loops - GeeksforGeeks
List comprehension includes brackets consisting of expression, which is executed for each element, and the for loop to iterate over each element in the list. newList = [expression(element) for element in oldList if condition] ... Explanation: ...
Published   1 week ago
🌐
GeeksforGeeks
geeksforgeeks.org › python › loops-in-python
Loops in Python - GeeksforGeeks
Python programming language allows to use one loop inside another loop which is called nested loop. Following example illustrates the concept. Python · from __future__ import print_function for i in range(1, 5): for j in range(i): print(i, end=' ') print() Output · 1 2 2 3 3 3 4 4 4 4 ·
Published   5 days ago
🌐
Programiz
programiz.com › java-programming › nested-loop
Nested Loop in Java (With Examples)
.. .... Week: 2 Day: 1 Day: 2 Day: 3 .... .. .... .... .. .... Here you can see that the output of both Example 1 and Example 2 is the same. We can use the nested loop in Java to create patterns like full pyramid, half pyramid, inverted pyramid, and so on. Here is a program to create a half pyramid pattern using nested loops. class Main { public static void main(String[] args) { int rows = 5; // outer loop for (int i = 1; i <= rows; ++i) { // inner loop to print the numbers for (int j = 1; j <= i; ++j) { System.out.print(j + " "); } System.out.println(""); } } }
🌐
OpenStax
openstax.org › books › introduction-python-programming › pages › 5-3-nested-loops
5.3 Nested loops - Introduction to Python Programming | OpenStax
March 13, 2024 - The outer loop can be implemented using a for loop iterating over the provided list, and the inner loop iterates over all even numbers less than a given number from the list using a while loop. numbers = [12, 5, 3] i = 0 for n in numbers: while ...
Top answer
1 of 2
4

The odd integer constants in the OP code don't make a lot of sense (even if they might work.)

One variable counting up while another counts down can be a bit like Zero Mostel's "One long staircase just going up, and one even longer coming down.." Hard to envision.

Try the following:

#include <stdio.h>

int main() {
    for( int r = 1; r < 7; r++ ) { // output 6 rows
        for( int b = r; b <= 7; b++ ) // 1=>7, then 2=>7, then 3=>7... easy!
            putchar( 'B' ); // no need to engage all of printf() for a character
        putchar( '\n' );
    }

    return 0;
}
BBBBBBB
BBBBBB
BBBBB
BBBB
BBB
BB

In essence, one can imagine that the floor (the starting point) gets progressively higher, but the ceiling does not move.


Noticed that you ask, in the comments below your question, "What is the correct, efficient way...? "
Here is one way that does not use nested loops:

int main() {
    char *bees = "BBBBBBB";

    for( int i = 0; bees[i+1]; i++ ) // "+1" because pattern ends with "BB"
        puts( bees + i );

    return 0;
}
2 of 2
0

It is much easier if you use functions and can test it with different numbers.

void printPattern(unsigned nrows)
{
    for(unsigned row = nrows; row > 0; row--)
    {
        for(unsigned col = 0; col <= row; col++)
            printf("B");
    printf("\n");
    }
}


int main()
{
    printPattern(7);
    printf("---------------------\n");
    printPattern(3);
    printf("---------------------\n");
    printPattern(1);
    printf("---------------------\n");
    printPattern(0);
    printf("---------------------\n");
    printPattern(15);
    printf("---------------------\n");
}

https://godbolt.org/z/xjzMPczPE