"jump" in a 'for' cycle

edited February 2010 in Science & Tech
Hi, to put it simply I need to "jump" in a 'for' cycle. For a better understanding an exmaple always helps :)
clear all;
j = 1;
for i = 1:20 
   result(j,1) = i; % this is just for storing of the variable 'i' that is involved in the first "for" cycle
   j = j + 1; % adding another row for the variable "result" 
   if i == 10
      i = i+2;
   end
end

When the variable 'i' has the value of 10 I need to "jump" two rows with the 'i' index and countinue again with an increment of 1. I don't know why this code doesn't work.

Could someone help me with this issue please ?

Thanks in advance !

Comments

  • edited February 2010
    I'm stunted,
    I've tried the same thing in C# and it worked perfectly
    What language is this?
  • ThraxThrax 🐌 Austin, TX Icrontian
    edited February 2010
    Matlab, as this post's host forum indicates.
  • edited February 2010
    hmm...
    If it's any help this is as it should look in C#
    for (int i = 0; i <= 20; i++)
    {
    Console.WriteLine(i.ToString());

    if (i == 10)
    i += 2;
    }

    I don't really think it will but I shan't know till I try
  • shwaipshwaip bluffin' with my muffin Icrontian
    edited February 2010
    each time the for loop starts, it takes the next value of i from the array that you are "for" looping over. So you are incrementing i by one, but then as soon as the loop ends, it just picks the next "i" from your array.


    can you give an example of an output "result" array that you want to see?
Sign In or Register to comment.