This loop should learn w = 2 and instead reports an astronomically wrong number. Nothing is wrong with the gradient — the LEARNING RATE is so large that every step overshoots the bottom and lands higher up the other side, doubling the error forever. Fix the one knob.
The break is on line 3 — but read the whole snippet first.