[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Re: while/for statement — what's wrong in a code?
From: |
Liam Groener |
Subject: |
Re: while/for statement — what's wrong in a code? |
Date: |
Sat, 30 Apr 2011 03:15:56 -0700 |
On Apr 30, 2011, at 2:53 AM, alhaim wrote:
>
> Hi everybody. This is my Octave code
>
> for K= 1:10
> while ( p < 1 )
> ceil(log2(K)) + 1/(1-(1-p)^K) %function
> p = p + sens;
> K
> endwhile;
> endfor
>
> K
>
> and here is an output:
>
> ans = 10.000
> K = 1
> ans = 5.0000
> K = 1
> ans = 3.3333
> K = 1
> ans = 2.5000
> K = 1
> ans = 2
> K = 1
> ans = 1.6667
> K = 1
> ans = 1.4286
> K = 1
> ans = 1.2500
> K = 1
> ans = 1.1111
> K = 1
> ans = 1
> K = 1
> K = 10
>
> So, as you can see -- in inner while statement value of K is fixed to 1.
> What I am supposed to do to vary this value between 1 and 10. Why it is not
Before the start of the for loop initialize p to 0 or whatever? The way you've
written it, p will always be greater than 1 for all K's above 1.