Mathematica 9 is now available
Student Support Forum
Student Support Forum: 'exiting "while"loop' topicStudent Support Forum > General > "exiting "while"loop"

Next Comment >Help | Reply To Topic
Author Comment/Response
Randy Silvers
04/29/03 1:19pm

I am preparing to write a command that will test 1000 possibilities to search for a false result. Consequently, I want the command to cease execution when either the 1000 iterations have completed or the result is false. I try the following command, just to see if it works, but instead of exiting the loop, the kernel gets stuck in an infinite loop that cannot even be aborted. Why?

The output of the following should be 1 then 2 then 3 and that is it, but instead, it continues to print 3. It seems that I have the loop exiting when either 10 iterations or 'match' becomes False. I have set it to set 'match' to False on the third iteration, simply to test this exiting portion, but this is failing.

n=1; match=True

While[n < 10 && match == True, Print[n]; n = n + 1; If[n = 3, match = False]]

URL: ,

Subject (listing for 'exiting "while"loop')
Author Date Posted
exiting "while"loop Randy Silvers 04/29/03 1:19pm
Re: exiting RAyRAy 05/03/03 8:13pm
Re: exiting RazroRog 05/07/03 07:39am
Next Comment >Help | Reply To Topic