Path: news.mathworks.com!not-for-mail
From: <HIDDEN>
Newsgroups: comp.soft-sys.matlab
Subject: Re: print prime
Date: Thu, 1 Oct 2009 14:19:03 +0000 (UTC)
Organization: Magnitude
Lines: 32
Message-ID: <ha2don$gka$1@fred.mathworks.com>
References: <h9fob7$hs7$1@fred.mathworks.com>
Reply-To: <HIDDEN>
NNTP-Posting-Host: webapp-05-blr.mathworks.com
Content-Type: text/plain; charset="ISO-8859-1"
Content-Transfer-Encoding: 8bit
X-Trace: fred.mathworks.com 1254406743 17034 172.30.248.35 (1 Oct 2009 14:19:03 GMT)
X-Complaints-To: news@mathworks.com
NNTP-Posting-Date: Thu, 1 Oct 2009 14:19:03 +0000 (UTC)
X-Newsreader: MATLAB Central Newsreader 865475
Xref: news.mathworks.com comp.soft-sys.matlab:574238


"John Wong" <gokoproject@gmail.com> wrote in message <h9fob7$hs7$1@fred.mathworks.com>...
> I wrote a program, but this is so buggy I guess?
> I have this P4 2.6Ghz pc & 1GB Ram, I guess it's running out of memory or something. 
> 
> Some numbers it will print not a prime / is a prime.
> 
> Let say primeTest(1)
> it will say it's a prime
> 
> but when you do like primeTest(10)
> nothing shows instead, on the bottom of the matlab (where the start menu is located), it will say "busy". 
> 
> is there something i misunderstood my own program?
> 
> 
> function primeTest(x)
> n = 3;
> R=rem(x,n);
> while R ~= 0 & n < sqrt(x) & n < 10
>     n+2;
>     r=rem(x,n);
> end
> if R ~= 0
>     disp('Is a prime')
> else
>     disp('Not a prime')
> 
> end
> end

In your while loop your forget to assign n+2 to n which explains why you stay in thsi while loop and MATLAB stays busy:
replace n+2 by n = n+2