var b = 8; var a = 0; var c = 2; while(b != 0){ b = b - 1; c = c - 1; if(c == 0){ a++; c = 2; } } console.log(c);