Part 1 · Lesson 5 · 18 min read

The while Loop

Repeat while a condition is true. Taking a number apart digit by digit, and a clear rule for choosing between for and while.

On this page

  1. Repeat while a condition is true
  2. The while loop, next to for
  3. The digit loop: n % 10 and Math.floor(n / 10)
  4. Traced: the sum of the digits of 472
  5. Building a number: reverse
  6. Infinite loops, and how to avoid them
  7. do … while (rarely needed)
  8. for or while? A simple rule
  9. Practice questions (10)
  10. Make it stick

Repeat while a condition is true

A for loop is perfect when you know the range, such as 1 to N or 0 to length − 1. But sometimes you only know the stopping condition. Examples are “keep dividing until nothing is left”, “keep doubling until you pass 1000” and “keep asking until the password is right”. For these, use a while loop. A while loop is a loop that repeats its body for as long as a condition stays true.

The while loop, next to for

JavaScript
// for: start, check and update all in one linefor (let i = 1; i <= 3; i++) {  console.log(i);}// while: the same loop with the three parts spread outlet i = 1;              // start   (before the loop)while (i <= 3) {        // check  console.log(i);  i++;                  // update  (last line of the body — easy to forget!)}/* Output:123123*/

A while loop has only the check in its brackets. The start goes before the loop. The update goes inside the body, usually as the last line. The order of execution from Lesson 4 is the same: check, body, check, body, and so on, until a check fails and the loop ends.

The digit loop: n % 10 and Math.floor(n / 10)

A digit is one of the symbols 0 to 9 that make up a number. The number 472 has three digits. In Lesson 2 you took the digits off a three-digit number by writing the same two lines three times. A while loop can do it for a number of any length, because it keeps going until there are no digits left:

The digit loop: learn this shape by heart
while (n > 0) {
  const digit = n % 10;      // the last digit
  // ...use digit...
  n = Math.floor(n / 10);    // remove the last digit
}

Counting digits, adding digits, reversing a number, checking a palindrome number and finding Armstrong numbers all use this same loop. Only the line in the middle is different.

Traced: the sum of the digits of 472

step 1 / 13
Set up
let n = 472

The number to take apart.

▶let n = 472;2let sum = 0;3while (n > 0) {4  sum += n % 10;5  n = Math.floor(n / 10);6}7console.log(sum);
Variables
n472
Console
(nothing printed yet)
n loses one digit per iteration: 472 → 47 → 4 → 0. The loop stops when nothing is left. · interactive
Dry run · sum of digits of 472
n at checkn > 0?n % 10sum aftern after
472true2247
47true794
4true4130
0false—13(loop ends)

Building a number: reverse

Taking digits apart is half the skill. The other half is putting them back together. To reverse a number, you build a new number, rev, one digit at a time. rev * 10 moves every digit of rev one place to the left. This makes an empty place at the end. Then + digit fills that place.

JavaScript
let n = 1234;let rev = 0;while (n > 0) {  const digit = n % 10;      // take the last digit  rev = rev * 10 + digit;    // shift rev left, put the digit on the end  n = Math.floor(n / 10);    // drop the last digit}console.log(rev); // 4321
Dry run · reverse 1234
ndigit = n % 10rev = rev * 10 + digitn after
123440 × 10 + 4 = 4123
12334 × 10 + 3 = 4312
12243 × 10 + 2 = 4321
11432 × 10 + 1 = 43210

Infinite loops, and how to avoid them

A while loop stops only when its condition becomes false. If nothing in the body moves towards that, the loop runs forever. This is called an infinite loop:

JavaScript
let i = 1;while (i <= 5) {  console.log(i);  // i++ is missing, so i stays 1 and 1 is printed forever. Press Ctrl+C to stop.}

Before running any while loop, ask one question:

Ask: what line makes the condition false eventually?

Find that line. In the digit loop it is n = Math.floor(n / 10). The number n becomes smaller in every iteration, so it must reach 0. If you cannot point at such a line, you probably have an infinite loop. If one is already running, press Ctrl+C in the terminal to stop it.

do … while (rarely needed)

do { … } while (condition) is a loop that runs the body first and checks the condition afterwards. So the body always runs at least once. It helps in a case like the one below, where the number 0 still has one digit. But you will rarely need it in DSA.

JavaScript
let n = 0;let digits = 0;do {  digits++;  n = Math.floor(n / 10);} while (n > 0);console.log(digits); // 1  (0 has one digit; a plain while would say 0)

for or while? A simple rule

If you know…UseExamples
the range of values (from … to …)for1 to N, every item of an array, every character of a string
only when to stopwhileuntil n is 0, until a value passes a limit, two pointers meeting in the middle (Lesson 21)

Anything one loop can do, the other can do too. This rule only helps you pick the one that is easier to read.

Practice questions

Q1Count the digitsEasy

Count how many digits a non-negative whole number has.

Example 1
Input: 4729
Output: 4
Explanation: 4729 has the digits 4, 7, 2 and 9.
Example 2
Input: 7
Output: 1
Explanation: A one-digit number.
Example 3
Input: 0
Output: 1
Explanation: Edge case: 0 is written with one digit.
Stuck? Open one hint at a time
Hint 1
Each time you divide by 10 and drop the decimal part, the number loses one digit.
Hint 2
Count how many times you can do that before the number becomes 0. Be careful with the input 0 itself.
Show all 3 solutions with explanations
Approach 1Divide by 10 until nothing is left
The idea

Remove one digit in each iteration with Math.floor(n / 10), and count the iterations.

JavaScript
function countDigits(n) {  if (n === 0) return 1;       // the loop below would not run for 0  let count = 0;  while (n > 0) {    count++;    n = Math.floor(n / 10);  }  return count;}console.log(countDigits(4729)); // 4console.log(countDigits(7));    // 1console.log(countDigits(0));    // 1
How it works
Dry run · countDigits(4729)
n at checkcount aftern after
47291472
472247
4734
440
0(loop ends)
Approach 2Convert to text and measure its length
The idea

The number of digits is the number of characters in the number when it is written as text (a string).

JavaScript
function countDigits(n) {  return String(n).length;}console.log(countDigits(4729)); // 4console.log(countDigits(0));    // 1
How it works

String(4729) is "4729", which has length 4. It is short and correct for non-negative whole numbers.

Approach 3Logarithm
The idea

A logarithm tells you how many times you can divide by a base. A number with k digits is at least 10k−1 and less than 10k, so k = ⌊log₁₀ n⌋ + 1. (The symbol ⌊ ⌋ means “round down”.)

JavaScript
function countDigits(n) {  if (n === 0) return 1;  return Math.floor(Math.log10(n)) + 1;}console.log(countDigits(4729)); // 4console.log(countDigits(1000)); // 4
How it works

Math.log10(4729) is about 3.67. Rounding down gives 3, and adding 1 gives 4. This is a maths shortcut. It is good to know, but not required. Be careful: computers store decimals with small rounding errors, so for very large numbers (for example 999999999999999) this method can give a wrong answer.

Which approach should you use?

Learn Approach 1. It is the digit loop that every other question in this list builds on. Approach 2 is fine in everyday code.

Q2Sum of digitsEasy

Find the sum of the digits of n.

Example 1
Input: 4729
Output: 22
Explanation: 4 + 7 + 2 + 9 = 22.
Example 2
Input: 5
Output: 5
Explanation: Only one digit.
Stuck? Open one hint at a time
Hint 1
Use the digit loop. Each iteration gives you the last digit with n % 10.
Hint 2
Add that digit to a sum, then remove it with Math.floor(n / 10).
Show all 2 solutions with explanations
Approach 1Digit loop
The idea

Take the last digit, add it to the sum, and remove it. Repeat while digits remain.

JavaScript
function sumDigits(n) {  let sum = 0;  while (n > 0) {    sum += n % 10;    n = Math.floor(n / 10);  }  return sum;}console.log(sumDigits(4729)); // 22
How it works

This is the traced example from the lesson, put inside a function. It works for a number of any length.

Approach 2Loop over the characters of the text
The idea

Write the number as text. Then turn each character into a number and add them up.

JavaScript
function sumDigits(n) {  let sum = 0;  for (const ch of String(n)) {    sum += Number(ch);  }  return sum;}console.log(sumDigits(4729)); // 22
How it works

for (const ch of text) is a loop that visits every character of the text one by one (Lesson 9). Number("7") turns the character into the number 7.

Which approach should you use?

Interviewers usually expect Approach 1, because it uses numbers only. Approach 2 is also correct and easy to read.

Q3Reverse a numberEasy

Reverse the digits of a positive number.

Example 1
Input: 1234
Output: 4321
Explanation: The digits in the opposite order.
Example 2
Input: 1200
Output: 21
Explanation: Reversed, the digits are 0021. Leading zeros are not written in a number, so the answer is 21.
Stuck? Open one hint at a time
Hint 1
Take the digits off from the right, one at a time.
Hint 2
To add a digit to the end of a number rev, multiply rev by 10 and add the digit: rev = rev * 10 + digit.
Show all 2 solutions with explanations
Approach 1Build the reverse digit by digit
The idea

Take the last digit of n and attach it to the end of rev. Repeat until n is 0.

JavaScript
function reverseNumber(n) {  let rev = 0;  while (n > 0) {    rev = rev * 10 + (n % 10);    n = Math.floor(n / 10);  }  return rev;}console.log(reverseNumber(1234)); // 4321console.log(reverseNumber(1200)); // 21
How it works
Dry run · reverseNumber(1234)
ndigitrev = rev × 10 + digit
123444
123343
122432
114321
Approach 2Reverse the text
The idea

Turn the number into text, reverse the characters, and turn the result back into a number.

JavaScript
function reverseNumber(n) {  return Number(String(n).split("").reverse().join(""));}console.log(reverseNumber(1234)); // 4321console.log(reverseNumber(1200)); // 21
How it works

split("") makes a list of single characters. reverse() reverses the list. join("") joins the list back into text. Number("0021") is 21.

Which approach should you use?

Approach 1 is the answer interviewers expect. LeetCode 7 (Reverse Integer) adds negative numbers and a size limit (the result must fit in a 32-bit integer). Handle the sign separately and check the limit before you return.

Q4Palindrome numberEasy

Return true if the number reads the same forwards and backwards. (LeetCode 9.)

Example 1
Input: 121
Output: true
Explanation: Reversed, 121 is still 121.
Example 2
Input: 123
Output: false
Explanation: Reversed, 123 is 321, which is different.
Example 3
Input: 10
Output: false
Explanation: Reversed, 10 is 01, which is 1.
Stuck? Open one hint at a time
Hint 1
A palindrome is something that reads the same forwards and backwards. A palindrome number equals its own reverse. You already know how to reverse a number.
Hint 2
The digit loop changes n. Save a copy of the original before the loop so you can compare at the end.
Show all 3 solutions with explanations
Approach 1Reverse it and compare
The idea

Build the reverse of n, then check whether it equals the original.

JavaScript
function isPalindromeNumber(n) {  const original = n;          // the loop will change n  let rev = 0;  while (n > 0) {    rev = rev * 10 + (n % 10);    n = Math.floor(n / 10);  }  return rev === original;}console.log(isPalindromeNumber(121));  // trueconsole.log(isPalindromeNumber(123));  // falseconsole.log(isPalindromeNumber(10));   // false
How it works

A common bug is comparing rev === n after the loop. By then n is 0. Saving original first fixes it.

Approach 2Compare digits from both ends as text
The idea

Write the number as text. Compare the first and last characters, then move both positions towards the middle.

JavaScript
function isPalindromeNumber(n) {  const s = String(n);  let left = 0, right = s.length - 1;  while (left < right) {    if (s[left] !== s[right]) return false;    left++;    right--;  }  return true;}console.log(isPalindromeNumber(1221)); // trueconsole.log(isPalindromeNumber(123));  // false
How it works

This is the two pointers technique. A pointer here is just a variable that holds a position (left and right). You will meet this technique again in Lessons 8, 9 and 21. The loop stops at the first mismatch.

Approach 3Reverse only half of the number
The idea

Move digits from n into rev until rev is at least as large as n. At that point you have reversed half of the number. Then compare the two halves.

JavaScript
function isPalindromeNumber(n) {  if (n < 0 || (n % 10 === 0 && n !== 0)) return false;   // e.g. 10, 120  let rev = 0;  while (n > rev) {    rev = rev * 10 + (n % 10);    n = Math.floor(n / 10);  }  // even length: n === rev;  odd length: drop the middle digit from rev  return n === rev || n === Math.floor(rev / 10);}console.log(isPalindromeNumber(1221));  // trueconsole.log(isPalindromeNumber(12321)); // trueconsole.log(isPalindromeNumber(10));    // false
How it works

For 12321: after three iterations n = 12 and rev = 123; Math.floor(123 / 10) = 12 = n, so it is a palindrome. Only half of the digits are processed, and the reversed number can never become too large. This is the follow-up answer for LeetCode 9.

Which approach should you use?

Start with Approach 1, because it is clear and correct. If the interviewer says not to convert to text, use Approach 1 or 3. Approach 3 is the most efficient.

Q5Smallest power of 2 that is at least NEasy

Find the smallest power of 2 (1, 2, 4, 8, …) that is greater than or equal to N.

Example 1
Input: 20
Output: 32
Explanation: The powers of 2 are 1, 2, 4, 8, 16, 32 and so on. 16 is too small. 32 is the first one that is 20 or more.
Example 2
Input: 64
Output: 64
Explanation: 64 is already a power of 2.
Example 3
Input: 1
Output: 1
Explanation: 1 is 2⁰.
Stuck? Open one hint at a time
Hint 1
You do not know how many doublings you need. You only know when to stop. Which loop fits?
Hint 2
Start at 1 and double while the value is still smaller than N.
Show all 2 solutions with explanations
Approach 1Keep doubling
The idea

Start at 1 and multiply by 2 until the value is at least N.

JavaScript
function nextPowerOfTwo(N) {  let p = 1;  while (p < N) {    p *= 2;  }  return p;}console.log(nextPowerOfTwo(20)); // 32console.log(nextPowerOfTwo(64)); // 64console.log(nextPowerOfTwo(1));  // 1
How it works

Use p < N, not p <= N; otherwise for N = 64 the loop doubles once more and returns 128.

Approach 2Logarithm
The idea

The power you need is ⌈log₂ N⌉ (the logarithm to base 2, rounded up). The answer is 2 raised to that power.

JavaScript
function nextPowerOfTwo(N) {  return 2 ** Math.ceil(Math.log2(N));}console.log(nextPowerOfTwo(20)); // 32console.log(nextPowerOfTwo(64)); // 64
How it works

Math.log2(20) is about 4.32. Rounding up gives 5, and 2⁵ = 32. This is a one-line maths shortcut. For very large N (above about 5 × 10¹⁴), rounding errors in decimals can make it give a wrong answer.

Which approach should you use?

Approach 1 is the clearest example of when to use while. Approach 2 is shorter, but you need to remember the maths.

Q6Count the even digitsEasy

How many digits of n are even?

Example 1
Input: 4729
Output: 2
Explanation: The digits 4 and 2 are even; 7 and 9 are odd.
Example 2
Input: 2468
Output: 4
Explanation: Every digit is even.
Stuck? Open one hint at a time
Hint 1
Use the digit loop to visit each digit.
Hint 2
Inside the loop, add 1 to a counter when the digit is even.
Show all 2 solutions with explanations
Approach 1Digit loop with an if
The idea

Take each digit with n % 10; count it if digit % 2 === 0.

JavaScript
function countEvenDigits(n) {  let count = 0;  while (n > 0) {    const digit = n % 10;    if (digit % 2 === 0) count++;    n = Math.floor(n / 10);  }  return count;}console.log(countEvenDigits(4729)); // 2console.log(countEvenDigits(2468)); // 4
How it works

This combines Lessons 3 and 5: a condition inside the digit loop. Most real problems are made of small building blocks like this.

Approach 2Loop over the characters
The idea

Check each character of the number when it is written as text.

JavaScript
function countEvenDigits(n) {  let count = 0;  for (const ch of String(n)) {    if (Number(ch) % 2 === 0) count++;  }  return count;}console.log(countEvenDigits(4729)); // 2
How it works

This is the same idea, but it reads the digits from left to right instead of right to left. The order does not matter for counting.

Which approach should you use?

Both are correct. Approach 1 uses only arithmetic (maths with numbers), which is what most interviewers expect for digit questions.

Q7Armstrong numberMedium

An Armstrong number is a number that equals the sum of its digits, each raised to the power of the number of digits. Check whether n is one.

Example 1
Input: 153
Output: true
Explanation: 3 digits: 1³ + 5³ + 3³ = 1 + 125 + 27 = 153.
Example 2
Input: 9474
Output: true
Explanation: 4 digits: 9⁴ + 4⁴ + 7⁴ + 4⁴ = 6561 + 256 + 2401 + 256 = 9474.
Example 3
Input: 123
Output: false
Explanation: 1³ + 2³ + 3³ = 36, which is not 123.
Stuck? Open one hint at a time
Hint 1
You need two things: the number of digits k, and the sum of each digit raised to the power k (a digit to the power 3 means digit × digit × digit).
Hint 2
Do it in two passes. The first pass counts the digits using a copy of n. The second pass builds the sum.
Show all 2 solutions with explanations
Approach 1Two digit loops
The idea
  1. Count the digits (k) using a copy of n.
  2. Loop again, adding each digit to the power k.
  3. Compare the sum with the original number.
JavaScript
function isArmstrong(n) {  const original = n;  let k = 0, temp = n;           // pass 1: count digits on a copy  while (temp > 0) {    k++;    temp = Math.floor(temp / 10);  }  let sum = 0;                   // pass 2: sum of digit^k  while (n > 0) {    sum += (n % 10) ** k;    n = Math.floor(n / 10);  }  return sum === original;}console.log(isArmstrong(153));  // trueconsole.log(isArmstrong(9474)); // trueconsole.log(isArmstrong(123));  // false
How it works

The first loop uses its own copy (temp), so n is still unchanged when the second loop runs. Splitting a problem into two simple passes is a good interview answer.

Approach 2Use the text length for k
The idea

Get the digit count from the length of the text, then do a single digit loop.

JavaScript
function isArmstrong(n) {  const k = String(n).length;  let sum = 0, temp = n;  while (temp > 0) {    sum += (temp % 10) ** k;    temp = Math.floor(temp / 10);  }  return sum === n;}console.log(isArmstrong(153)); // trueconsole.log(isArmstrong(370)); // true
How it works

This is shorter, with one loop instead of two. Working on temp keeps n available for the final comparison.

Which approach should you use?

Both are correct. Approach 2 is shorter. Approach 1 shows that you can do everything with arithmetic, which some interviewers ask for.

Q8Collatz stepsMedium

If n is even, halve it. If n is odd, make it 3n + 1. Count the steps until n becomes 1.

Example 1
Input: 6
Output: 8
Explanation: 6 → 3 → 10 → 5 → 16 → 8 → 4 → 2 → 1 is 8 steps.
Example 2
Input: 1
Output: 0
Explanation: Already 1, so no steps are needed.
Stuck? Open one hint at a time
Hint 1
You cannot know the number of steps in advance, because n sometimes goes up. Which loop fits?
Hint 2
Loop while n !== 1. Inside the loop, apply the even or odd rule and count one step.
Show all 2 solutions with explanations
Approach 1while with if / else
The idea

Repeat until n is 1. If n is even, halve it. Otherwise make it 3n + 1. Count each step.

JavaScript
function collatzSteps(n) {  let steps = 0;  while (n !== 1) {    if (n % 2 === 0) {      n = n / 2;    } else {      n = 3 * n + 1;    }    steps++;  }  return steps;}console.log(collatzSteps(6)); // 8console.log(collatzSteps(1)); // 0
How it works

This is the clearest case for while. The only thing you know is the stopping condition.

Approach 2while with a ternary update
The idea

The same loop, but it picks the next value in one line with a ternary (Lesson 3).

JavaScript
function collatzSteps(n) {  let steps = 0;  while (n !== 1) {    n = n % 2 === 0 ? n / 2 : 3 * n + 1;    steps++;  }  return steps;}console.log(collatzSteps(6)); // 8
How it works

This is shorter, and the update is in one place. That makes it easy to check that n changes in every iteration.

Which approach should you use?

Either one is fine. Use the version that you find easier to read aloud.

Q9Greatest common divisor (GCD)Medium

Find the largest number that divides both a and b exactly. This is the greatest common divisor (GCD).

Example 1
Input: 48, 18
Output: 6
Explanation: The divisors of 18 are 1, 2, 3, 6, 9, 18. The largest that also divides 48 is 6.
Example 2
Input: 17, 5
Output: 1
Explanation: 17 and 5 share no divisor other than 1.
Stuck? Open one hint at a time
Hint 1
Simple idea: try every number from the smaller input down to 1. Stop at the first one that divides both.
Hint 2
Faster idea (Euclid, a Greek mathematician): gcd(a, b) = gcd(b, a % b), and gcd(a, 0) = a.
Show all 3 solutions with explanations
Approach 1Try every candidate, largest first
The idea

Start at the smaller of the two numbers and count down. The first number that divides both is the answer.

JavaScript
function gcd(a, b) {  for (let d = Math.min(a, b); d >= 1; d--) {    if (a % d === 0 && b % d === 0) return d;  }  return 1;}console.log(gcd(48, 18)); // 6console.log(gcd(17, 5));  // 1
How it works

This is easy to understand, but for large numbers it may try millions of candidates.

Approach 2Euclid's algorithm with %
The idea

Replace the pair (a, b) with (b, a % b) again and again until b is 0. Then a is the answer.

JavaScript
function gcd(a, b) {  while (b !== 0) {    const r = a % b;    a = b;    b = r;  }  return a;}console.log(gcd(48, 18)); // 6console.log(gcd(17, 5));  // 1
How it works
Dry run · gcd(48, 18)
abr = a % b
481812
18126
1260
60(loop ends → 6)
Approach 3Euclid's algorithm with subtraction
The idea

Subtract the smaller number from the larger one until they are equal.

JavaScript
function gcd(a, b) {  while (a !== b) {    if (a > b) a -= b;    else b -= a;  }  return a;}console.log(gcd(48, 18)); // 6
How it works

This is the original form of the method. It gives the same answer, but % does many subtractions in one step, so Approach 2 is much faster. (This version assumes both numbers are positive.)

Which approach should you use?

Use Approach 2. It is over 2,000 years old and is still the standard method. It needs very few iterations, even for huge numbers.

Q10Steps to reduce a number to zeroEasy

If n is even, divide it by 2; if it is odd, subtract 1. Return how many steps it takes to reach 0. (LeetCode 1342.)

Example 1
Input: 14
Output: 6
Explanation: 14 → 7 (halve) → 6 (subtract 1) → 3 → 2 → 1 → 0. That is 6 steps.
Example 2
Input: 8
Output: 4
Explanation: 8 → 4 → 2 → 1 → 0.
Stuck? Open one hint at a time
Hint 1
Repeat while n is greater than 0. If n is even, divide it by 2. Otherwise, subtract 1.
Hint 2
Count every step.
Show all 2 solutions with explanations
Approach 1Simulate the steps
The idea

Follow the rule exactly as it is described, and count the steps.

JavaScript
function numberOfSteps(n) {  let steps = 0;  while (n > 0) {    n = n % 2 === 0 ? n / 2 : n - 1;    steps++;  }  return steps;}console.log(numberOfSteps(14)); // 6console.log(numberOfSteps(8));  // 4
How it works

This is a direct simulation (you do what the question says, step by step). Each even step halves n, so the loop runs only a few dozen times, even for very large numbers.

Approach 2Count using the binary form
The idea

Binary is the way computers write numbers using only 0 and 1. In binary, halving an even number removes its last digit (a 0). Subtracting 1 from an odd number turns its last 1 into 0. So the number of steps is (number of binary digits − 1) + (number of 1s).

JavaScript
function numberOfSteps(n) {  if (n === 0) return 0;  const bits = n.toString(2);                 // 14 → "1110"  let ones = 0;  for (const b of bits) if (b === "1") ones++;  return bits.length - 1 + ones;              // 3 + 3 = 6}console.log(numberOfSteps(14)); // 6console.log(numberOfSteps(8));  // 4
How it works

n.toString(2) writes n in binary. This is a preview of bit manipulation (working with the 0s and 1s of a number; Lesson 58). The simulation is perfectly fine in an interview.

Which approach should you use?

Give Approach 1. Approach 2 is a nice extra point to mention if you have time.

Make it stick

Make it stick — close this page, then
  1. Write the digit loop from memory, and say which line guarantees it ends.
  2. Reverse 905 on paper with a dry-run table. (Answer: 509.)
  3. Rewrite for (let i = 10; i > 0; i -= 3) as a while loop and list the values of i.

Revisit schedule: solve two of the questions again tomorrow, again in 3 days, and once more in a week — without looking at the answers. Each time it will feel easier. That is the memory forming.

Next lesson: loops inside other loops (nested loops), and how to draw patterns with them.

Practise on LeetCode

Real interview problems that use exactly what this lesson teaches. Solve them in JavaScript after the practice questions above.

Published by Jainik · Last updated · How these lessons are made

Keep learning

Related series