Information about cookies on this page

Our website uses cookies to ensure the functionality of the website, to collect and analyze information about the performance and usage of the website. Privacy Policy

  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in
  
  • Courses
    • Discord
    • Twitter
    • Linkedin
    • Facebook
    • Instagram
  • Pricing
  • English
  • Čeština
  • Deutsch
  • Русский
Sign inStart free
  • Courses
  • Pricing

Community

Sign in

An Endless Loop

Run the program in the editor. The dog turns and then… just stands there. The program keeps running, though, and after a while the editor stops it with a message that it ran for too long.

Here's what happened: the Repeat until at the goal loop is empty. Before every pass, the dog checks whether it's at the goal. It isn't, so it carries out the blocks in the loop: none. And it checks again whether it's at the goal. It still isn't, because it hasn't moved. And so on, over and over, forever. The Move forward block that should have been in the loop is under it, and the program never gets there.

Such a loop is called an endless loop (or an infinite loop), and it's one of the most common bugs in programs. The computer gets "stuck" in it: it doesn't crash or report anything, it just keeps doing the same thing. That's why the editor stops it by itself after a while.

How to avoid endless loops: for every loop with a condition, ask yourself whether every pass brings it closer to the end. Here, every pass has to move the dog one step closer to the goal.

Instructions

  1. 1

    Fix the program so that the dog reaches the goal on both maps.

Back

7/8

  1. 1. Repeat Until at the Goal
  2. 2. Stairs of Any Height
  3. 3. While There's a Path Ahead
  4. 4. Corner After Corner
  5. 5. Quiz: Only What's Ahead
  6. 6. Bones All the Way
  7. 7. An Endless Loop
  8. 8. Summary
Next

Try it yourself

Do this exercise right here in your browser. No account needed.