Computer Science Canada A simple "exit when" question |
Author: | bigbut600 [ Wed Oct 08, 2008 9:34 pm ] | ||
Post subject: | A simple "exit when" question | ||
I need to exit a loop when the last number is finally outputted. But I seem to be doing something wrong because I am expecting the number 1 to be listed in the execution, but also I need to exit the loop and still have that number 1 there. If I put, exit when factor = 1 it will exit the loop, but the number 1 won't even be outputted. I don't even think it is the write way to exit. Any suggestion would be great. Thanks! Here's my work. Look near the end.
|
Author: | The_Bean [ Wed Oct 08, 2008 9:45 pm ] |
Post subject: | Re: A simple "exit when" question |
Mod Edit: that was a complete solution to the assignment, not an answer relating to the question. |
Author: | gitoxa [ Wed Oct 08, 2008 9:57 pm ] | ||
Post subject: | RE:A simple "exit when" question | ||
A simpler way to find out if a number is a factor would be when this statement is true
The reason your program isn't outputting 1 is because the statement 50 div 40 is equal to 1. The best way to figure out a problem like this is to echo all variables that could cause the problem to the screen. If you do this, you'll see your program exits the loop long before the count is up to 50. |