This reminds me of Eiffel, where loop (in)variants had to be explicitly declared, as part of its design-by-contract dogma.
for (let i = 0; i < someVar; i++) {
invariant: i < 10000;
console.log(i);
}
along with other kinds of contract, like preconditions and postconditions - https://github.com/codemix/babel-plugin-contracts