Section 3: Code Critic's Code Conundrums

This section is dedicated to the most egregious examples of code gone wrong.

Case #1: The Infinite Loop of Doom

A simple while loop turned into an eternal nightmare.

            <script>
            var i = 0;
            while (i < 10) {
                i++;
            }
            </script>
            

Why: Because someone forgot to break out of the loop. See the next example

Case #2: The Regex That Ate the World

A simple search function brought the entire system to its knees.

            <script>
            function findString(s) {
                var re = /.*?/;
                while (s.search(re) != -1) {
                    s = s.slice(s.search(re) + re.length);
                }
            }
            </script>
            

Why: Because someone thought a non-capturing group would fix it. See the next example

Case #3: The Database of Despair

A simple query turned into a never-ending cycle of despair.

            <script>
            db.query("SELECT * FROM table WHERE condition = 'true'");
            </script>
            

Why: Because someone forgot to close the connection. See the next example