help-octave
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

while/for statement — what's wrong in a code?


From: alhaim
Subject: while/for statement — what's wrong in a code?
Date: Sat, 30 Apr 2011 02:53:28 -0700 (PDT)

0 down vote favorite
        

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
working? I have no idea why this inner while statement is proceed only once?
--
View this message in context: 
http://octave.1599824.n4.nabble.com/while-for-statement-what-s-wrong-in-a-code-tp3485616p3485616.html
Sent from the Octave - General mailing list archive at Nabble.com.


reply via email to

[Prev in Thread] Current Thread [Next in Thread]