问题
Since there are technically 4 types of loops (for, while, repeat, and goto/lbl), which one is the fastest to use "infinitely"? Here is what I mean:
while 1
End
repeat 0
End
lbl 1
goTo 1
for(n, 1, [number large enough to function as practically infinite]
End
Which of these is the fastest, or is there an even faster one?
回答1:
In terms of both size and speed, the repeat and while loops are the fastest.
While 1
and Repeat 0
are both 2 bytes, while End
is 1. In terms of space, they are both 4 bytes.
In terms of speed, the same is true. Just try making a simple program that loops to infinity and time it.
TL;DR: While 1: End
and Repeat 0: End
回答2:
Technically the fastest is:
AsmPrgm
18FE
which has to be run as an assembly program.
This is using Z80 assembly to create an infinite (unstoppable except by the reset button) loop. The code is run directly by the processor, so the OS doesn't need to spend time interpreting it.
来源:https://stackoverflow.com/questions/41028809/what-is-the-fastest-infinite-loop-in-ti-84-basic