Repeating with while
Keep going while something is true.
Repeating with while is a free Javascript for Kids lesson on CoddyKit — lesson 3 of 4. You can read the complete lesson below for free — then practise it hands-on in the browser with a built-in code editor and a 24/7 AI tutor. It is part of the Javascript for Kids learning path, one of 4 lessons in the course, and your progress syncs across the web and the CoddyKit app.
Repeating with while 🔄
Hi, repeat ranger! 🌟 There is another loop called while!
It repeats while a rule is still true. 🪄
let i = 1
while (i <= 3) {
console.log(i)
i++
}While It Is True ✅
while keeps going AS LONG AS the rule is true.
When the rule becomes false, it stops! 🛑
let count = 0
while (count < 3) {
console.log("Loop! 🔁")
count++
}Do Not Forget to Change! ⚠️
VERY important: inside a while loop, you must change the counter!
If you forget count++, the loop never stops! 😱
let count = 1
while (count <= 3) {
console.log("Count " + count)
count++
}Counting with while 🔢
Let us count to 5 using while!
Start at 1, go up until we pass 5. ⬆️
let n = 1
while (n <= 5) {
console.log(n)
n++
}Blowing Bubbles 🫧
Let us blow bubbles while we have breath left!
Each loop blows one bubble. 🫧
let breath = 4
while (breath > 0) {
console.log("Bubble! 🫧")
breath--
}Counting Down ⬇️
While loops can count DOWN too! Use -- to subtract one.
5, 4, 3, 2, 1! 🚀
let n = 5
while (n > 0) {
console.log(n)
n--
}Eating Cookies 🍪
Let us eat cookies while there are some left!
Yum yum yum! 😋
let cookies = 3
while (cookies > 0) {
console.log("Eating a cookie! 🍪")
cookies--
}Climbing Stairs 🪜
Let us climb stairs while we are not at the top!
Step by step. 🚶
let step = 1
while (step <= 4) {
console.log("Step " + step + " 🪜")
step++
}for vs while 🤔
A for loop and a while loop can do the same thing!
Use for when you know how many times. Use while when you wait for a rule. 🎯
let i = 1
while (i <= 3) {
console.log("Same as for! " + i)
i++
}Filling a Cup 🥤
Let us add water while the cup is not full!
Glug glug glug! 💧
let water = 0
while (water < 3) {
water++
console.log("Water level: " + water + " 💧")
}Your while Loop 🧒
Change the number and watch the loop repeat!
Remember to keep i++ so it stops. 🛑
let i = 1
while (i <= 4) {
console.log("Hello " + i)
i++
}Quick Check ✅
While question! You can do it! 🔄
Repeat Ranger! 🏆
Brilliant! 🎉 Today you learned:
whilerepeats while a rule is true- Always change the counter so it stops
- You can count up with
++or down with--
You are a while wizard! ⭐
let i = 1
while (i <= 1) {
console.log("I learned while! 🎉")
i++
}Frequently asked questions
Is the “Repeating with while” lesson free?
Yes — the full text of “Repeating with while” is free to read here on the web, and the Javascript for Kids course includes 4 lessons in total. To practise it interactively (a built-in code editor and a 24/7 AI tutor) and unlock the rest of the Javascript for Kids course, upgrade to CoddyKit PRO.
What will I learn in “Repeating with while”?
Keep going while something is true. You practise Javascript for Kids with hands-on code you run directly in the browser, and a 24/7 AI tutor answers your questions as you work through the lesson.
Do I need any experience to start Javascript for Kids?
No prior experience is required. Javascript for Kids on CoddyKit is structured for beginners through advanced learners; this is — lesson 3 of 4, so you can start here or from the beginning and move at your own pace.
How long does the “Repeating with while” lesson take?
Most CoddyKit lessons take about 5–10 minutes. Each one is bite-sized and interactive, so you make steady progress and pick up exactly where you left off across the web and the app.
Can I write and run code in this Javascript for Kids lesson?
Yes. Every Javascript for Kids lesson includes a built-in code editor, so you write and run real code right in your browser and get instant AI feedback — no local setup required.
All lessons in this course
- Why We Use Loops
- Counting with a for Loop
- Repeating with while
- Drawing Patterns with Loops