[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
Simple (and probably stupid) question about for loops
From: |
John W. Eaton |
Subject: |
Simple (and probably stupid) question about for loops |
Date: |
Tue, 25 May 2010 10:42:46 -0400 |
On 25-May-2010, AlbFrigerio wrote:
| Hi everyone, I believe I'm really rusty in using Octave cause I'm trying to
| do a very simple thing (in my mind) but I cannot succed in it. I tried to
| read the guide and some posts on for loops, but I haven't managed anything.
|
| Here it is my question : is it possible to update the value of the for index
| inside the loop?
|
| For example, I wrote the following code :
|
| for k=1:10
| k
| if k==2
| k=5;
| endif
| endfor
|
| I'd like the output to be : 1 2 6 7 8 9 10 , but it always gives me 1 2 3 4
| ... 10 . It sounds like the k variable in the loop to be completely
| different from the one used in the loop.
It's not a different variable. The value is reset each time at the
top of the loop.
jwe