That's exactly what loops do. Simply put, they eliminate the need for brute-forcing and are a means of iteration using just a few lines of code.
Though if you're using the loop above and want to optimize it, you would either add -1 after .length, or change the comparison operator from <= to just <. Better the former.
"Hello world" is merely an example. I don't fully know what you're trying to accomplish, as the way it was worded hints at an entirely different possible solution not limited to JS, which would nonetheless be doubtful to operate on the DSi browser, let alone submit. Can you go into more detail about this code's background and what exactly you hope your code will do?