I am doing my first game snake, but I have a problem which appears sometime when I eat a rectangle and try to generate another my script crashes and I have an infinite loop.
var coincide = false; var cmpt; do { mangey = Math.random(); mangey *= canvas.height; t = mangey % 20; mangey -= t; mangex = Math.random(); mangex *= canvas.width; t = mangex % 20; mangex = mangex - t; for (cmpt = 0; cmpt < snake.length; cmpt++) { if ((snake[cmpt][0] == mangex) && (snake[cmpt][1] == mangey)) { coincide = true; alert(snake); console.log(mangex,mangey); } } } while ((coincide) || ((mangex > 480) || (mangex < 0)) || ((mangey > 380) || (mangey < 0)));