So I am programming in BASIC Right now, And I just finished our assignment, but I'm confused as To why a slight variation in loop makes the program work.
This is the working code:
CODE
Repeat
factors = 0
storage = Input("Enter a number ")
For counter = storage To 1 Step -1
If (storage Mod counter = 0)
factors = factors + 1
EndIf
Next
Until factors = 2
Print "Prime!"
As you can tell, that is a program that waits until the user inputs a prime number. My curosity stems from the fact that my first attempt at this program didn't work. I used another Repeat...Until instead of a for loop, and it did not work. It was something like this:
CODE
spy = 0
Repeat
factors = 0
storage = Input("Enter a number ")
Repeat
If (storage Mod counter = 0)
factors = factors + 1
EndIf
spy = spy + 1
Until (storage = spy)
Until factors = 2
Print "Prime!"
This code doesn't work, and I was wondering why?
(Well actually I think my code was like that, I accidently deleted my original code so this is based off of my memory.) If I can't get an answer, it's okay, as I've already done it with a For loop anyways.
I use the blitzbasic compiler. Thanks.
This post has been edited by Revitalized: 25 Sep, 2007 - 10:00 AM