Shape Rule
Jump sequence
Row 1 prints 1, row 2 prints 2 6, row 3 prints 3 7 10, and so on with shrinking jumps.

The increasing jump number triangle starts each row at i and jumps forward with a decreasing step m — a natural step after the continuous counter in Program 20. This tutorial covers the shape rule, step logic, a live preview, algorithm steps, worked JavaScript examples, edge cases, and complexity.
Jump sequence
Row 1 prints 1, row 2 prints 2 6, row 3 prints 3 7 10, and so on with shrinking jumps.
1..rows
for (let i = 1; i <= rows; i++) makes row i print exactly i numbers.
m -= 1 each jump
Set m = rows - 1 and k = i + m; after each append do m-- then k = k + m.
Same line / next line
Append i first, then k values in the inner loop; end each row with console.log(line).
1–15 rows
Pick a row count and draw the jump number triangle instantly in the browser.
Complexity
Total prints = rows(rows+1)/2; extra memory stays O(1).
An increasing jump number triangle prints each row starting at the row index, then jumps forward using a step that shrinks after every print. With rows = 5, the output is 1, 2 6, 3 7 10, 4 8 11 13, 5 9 12 14 15.
In JavaScript you append i first, set m = rows - 1 and k = i + m, then in the inner loop append k, do m--, and update k = k + m before the next value.
It combines nested loops with a changing step variable — a step up from Program 20’s simple counter.
Print i before the inner loop on every row.
Start at rows - 1 and decrease after each jump.
k = i + m first, then m -= 1 and k = k + m in the loop.
Follow Program 20; continue to Program 22 (odd-length rows) next.
In short: for each row i, print i, then use a decreasing step m to compute and print the remaining i - 1 values.
Given a positive integer rows, print an increasing jump number triangle: row i starts with i, then prints i - 1 more values computed by adding a decreasing step m.
// rows = 5 (conceptual shape)
// 1
// 2 6
// 3 7 10
// 4 8 11 13
// 5 9 12 14 15
for (let i = 1; i <= rows; i++) {
let line = i + " ";
let m = rows - 1;
let k = i + m;
for (let j = 1; j < i; j++) {
line += k + " ";
m--;
k = k + m;
}
console.log(line);
} | Item | Type | Description |
|---|---|---|
rows | int | Number of triangle lines to print (typically ≥ 1). |
m | int | Step size — starts at rows - 1, decreases after each jump. |
k | int | Next value to print — set to i + m before the inner loop. |
| Printed output | text | Row i has i spaced numbers with shrinking jumps. |
for i from 1 to rows:
line = i + " "
m = rows - 1
k = i + m
for j from 1 to i - 1:
append k + " " to line
m = m - 1
k = k + m
console.log(line) | Approach | Idea | Best for |
|---|---|---|
| Decreasing step m | 1, 2 6, 3 7 10, … | Learning and interviews |
| User-input rows | rows = parseInt(prompt(...)) | Flexible console programs |
| Custom initial step | m = 3 instead of rows - 1 | Tighter or wider jumps |
| Goal | Pattern |
|---|---|
| Walk each row | for (let i = 1; i <= rows; i++) |
| Print row start | line += i + " " |
| Init step | m = rows - 1 |
| First jump value | k = i + m |
| Inner loop | for (let j = 1; j < i; j++) |
| Update step | m -= 1 then k = k + m after each print |
| User input | rows = parseInt(prompt(...)) |
Same jump triangle — different ways to control rows and step size.
line += iEvery row begins with the row index
m = rows-1Initial jump size — reset each row
m = 3Override step in Example 3
m -= 1Decrease m after each k print — jumps shrink
Reach for this pattern when teaching variable step sizes and computed sequences inside nested loops.
Natural follow-up after Program 20 — introduces a decreasing step variable.
Outer/inner bound practice with an immediate visual check.
Combine loops with prompt() for a flexible row count.
Compare Program 20 (continuous counter) and Program 22 (odd-length rows) next.
This is a console teaching pattern — not how you build modern app screens.
Key benefit: one small program that locks in nested loops, output sequencing, and O(n²) thinking.
Choose a row count between 1 and 15 and draw the jump number triangle in the browser.
Three complete JavaScript programs — fixed row count, user input, and custom initial step for m. Click View Output to reveal sample results, or Try it Yourself to run the code live.
Print five rows of the jump number triangle with a decreasing step.
rows = 5Hard-coded height — ideal for first demos and screenshots.
const rows = 5;
for (let i = 1; i <= rows; i++) {
let line = i + " ";
let m = 4;
let k = i + m;
for (let j = 1; j < i; j++) {
line += k + " ";
m--;
k = k + m;
}
console.log(line);
} When i = 2, append 2, then m = 4 and k = 6 — the inner loop appends 6 once. When i = 3, append 3, then k = 7, m-- to 3, k = 10 — output 3 7 10. console.log(line) after the inner loop starts the next row.
Read the row count with prompt() instead of hard-coding 5.
Read rows with prompt() and parseInt(); set m = rows - 1 each row.
const rowsInput = prompt("Enter the number of rows:");
const rows = parseInt(rowsInput, 10);
for (let i = 1; i <= rows; i++) {
let line = i + " ";
let m = rows - 1;
let k = i + m;
for (let j = 1; j < i; j++) {
line += k + " ";
m--;
k = k + m;
}
console.log(line);
} Same nested-loop core as Example 1; only the source of rows changes. m = rows - 1 scales the initial jump with triangle height. Non-numeric input yields NaN with bare parseInt(prompt()) — validate with Number.isFinite for safer labs.
Use a fixed initial step instead of rows - 1.
m = 3Keep rows = 4 but start each row with m = 3 for tighter jumps.
const rows = 4;
for (let i = 1; i <= rows; i++) {
let line = i + " ";
let m = 3;
let k = i + m;
for (let j = 1; j < i; j++) {
line += k + " ";
m--;
k = k + m;
}
console.log(line);
} Change only the initial value of m — the inner loop and k = k + m logic stay the same. Smaller starting steps produce tighter jumps within each row.
console.log is built in; use prompt() when reading input. Set rows and loop variables i, j, k, m.
for (let i = 1; i <= rows; i++) then line += i + " " — row i prints i numbers.
m = rows - 1 and k = i + m set up the first jump in that row.
Print k, then m -= 1 and k = k + m to compute the next jump.
console.log(line) ends the row so the next outer iteration starts fresh.
Total prints: rows(rows+1)/2 — O(n²) time, O(1) extra memory.
rows = 5Trace each outer-loop value of i, the initial m, and the numbers printed on each row.
i | Init m | Jump sequence | Row output |
|---|---|---|---|
1 | 4 | 1 (no inner loop) | 1 |
2 | 4 → k=6 | 2, 6 | 2 6 |
3 | 4 → k=7, m=3 → k=10 | 3, 7, 10 | 3 7 10 |
4 | 4 → 8, 11, 13 | 4, 8, 11, 13 | 4 8 11 13 |
5 | 4 → 9, 12, 14, 15 | 5, 9, 12, 14, 15 | 5 9 12 14 15 |
Total number prints: 1 + 2 + 3 + 4 + 5 = 15 = 5×6/2.
Where this tiny pattern (and its loop structure) shows up beyond the homework prompt.
Clearest visual proof that outer and inner bounds interact.
Example: change j <= i and watch the shape change.
Foundation for inverted, pyramid, diamond, and hollow variants.
Example: use (i + j) % 2 for row+column parity grids.
Practice line += k + " " vs console.log(line) without complex math.
Example: put console.log(line) inside the inner loop by mistake.
Swap digits for letters, stars, or spaced output once the loop works.
Example: use line += k + " " for spaced digits on each row.
Triangular totals make O(n²) concrete for beginners.
Example: count printed digits for n = 10 still → 55.
Pair the pattern with Number.isFinite checks around parseInt(prompt()) and positive-row checks.
Example: reject rows <= 0 and re-prompt.
Pro Tip: when an interviewer asks for patterns, explain the outer/inner roles first — then write the loops. The story matters as much as the code.
Why this pattern earns a permanent spot in beginner JavaScript courses.
Wrong bounds show up immediately as a broken staircase.
Only loops and console output — no arrays or math libraries.
Invert, center, hollow, or change the fill character with small edits.
Streaming output needs no storage beyond loop counters.
Pro Tip: learn m = rows - 1 and k = i + m first; compare with custom step in Example 3.
Small habits that keep number-pattern code clean.
Reset m = rows - 1 at the start of each row — not once before all loops.
prompt()Check parseInt(prompt()) with Number.isFinite so bad input does not leave rows as NaN.
Only call console.log(line) after the inner loop finishes the row.
Write row i, initial m, and each k jump before coding.
Trace rows = 5 on paper before coding larger demos.
Pro Tip: if the output is a vertical list of single digits per line, you almost certainly put console.log(line) inside the inner loop.
Mistakes that commonly break jump number patterns.
Each digit lands on its own line — you get a column, not a triangle.
→ Use line += i + " " and line += k + " "; console.log(line) only after the inner loop.
Using j <= i prints one extra value per row.
→ Use for (let j = 1; j < i; j++) — only i - 1 jumps after printing i.
Skipping m -= 1 makes every jump the same size.
→ Always do m -= 1 then k = k + m after printing k.
Omitting console.log(line) glues every number onto one endless line.
→ Always end the row after the inner loop.
Letters or empty input yield NaN with bare parseInt(prompt()).
→ Validate with Number.isFinite and re-prompt on failure.
Check these inputs before calling the solution done.
Output is just 1 on one line.
Outer loop never runs — print nothing or show a message.
rows < 0Treat as invalid; re-prompt instead of silent empty output.
Output grows as n² characters — fine for labs, noisy for huge n.
parseInt(prompt()) yields NaN — validate with Number.isFinite first.
Declaring m once before all loops gives wrong jumps — reset inside each row.
When i = 1, the inner loop runs zero times — only 1 prints.
Try these variations to lock in the pattern.
k++ across rowsm = 2 or m = 6 instead of rows - 1rows(rows+1)/2 — O(n²) for n rows.line += k + " " stays on the line; console.log(line) advances — mix them carefully.rows > 0 for interactive programs; rows = 1 should print a single 1.Quick Takeaway: print i first, set m = rows - 1 and k = i + m, then loop with m -= 1 and k = k + m.
| Program | Time | Extra space |
|---|---|---|
| Nested loops (Examples 1–2) | O(rows²) | O(1) |
| Custom step (Example 3) | O(rows²) | O(1) |
The increasing jump number triangle is a compact lesson in variable step sizes: print i, set m = rows - 1, compute jumps with k = i + m, and shrink m after each print. Master the fixed-rows version, then try user input and a custom step value.
Practice the three examples above, then continue to Program 22 for odd-length number rows.
Reset m each row — use j < i for the inner loop and validate rows when reading input.
i before the inner loop on every rowm = rows - 1 inside each outer iterationfor (let j = 1; j < i; j++) for jump valuesparseInt(prompt()) with Number.isFinite before using rowsconsole.log(line) inside the inner jump loopj <= i — that prints one extra valuem -= 1 before updating krows = 1 edge casePrint the pattern the beginner-friendly way.
Jump + m -= 1
DefinitionRow start first
Coderows - 1, then m -= 1
CodeRow i prints i nums
ShapeO(n²) time
AnalysisEach row starts at i, then adds a decreasing step m to compute the next value. As m shrinks after each append, the jumps get smaller toward the end of the row — total prints still equal n(n+1)/2 for n rows.
Move on to the odd-length number rows pattern in the JavaScript number-pattern series.
12 people found this page helpful