The problem you have is that stop ends the program entirely instead of just breaking the loops. To fix this, instead or using For loops, you could use Repeat loops:
:1→D
:Repeat (D*E=C and D+E=B) or D=100
::1→E
::Repeat (D*E=C and D+E=B) or E=100
:::E+1→E
::End
::1+D→D
:End
You can ignore the extra colons, they are just there for clarity, but if you leave them the code will still work because they function identically to newlines.
The Repeat loops will break by themselves when the condition D*E=C and D+E=B
is met, but you have to handle the initialization and incrementing of the variables E
and D
yourself.
Also note that your factoring algorithm can fail if A
does not equal one. Consider dividing both B
and C
by A
, and then outputting A
as a constant factor.
Another error with your code is that you have too many End
statements, but fixing this would not fix the program, and it would still exit at the Stop
. An If
without a Then
does not need an End
, but only one line will be run if the condition is true. For example:
:If <condition>
:<one statement>
or
:If <condition>
:Then
:<statement 1>
:<statement 2>
:<statement ...>
:<statement n>
:End