Results 1 to 3 of 3

Math Help - Question in matlab

  1. #1
    Member
    Joined
    Sep 2009
    Posts
    162

    Question in matlab

    Hi All
    I want to ask question in matlab, Can I create if loop inside for loop such that if on condition of if hold then for loop must end, i.e How can we do the following
    For i = 1:2:10
    if mod(i,2)=0
    end
    else
    i
    end

    Best wishes
    Follow Math Help Forum on Facebook and Google+

  2. #2
    MHF Contributor alexmahone's Avatar
    Joined
    Oct 2008
    Posts
    1,074
    Thanks
    7
    Quote Originally Posted by raed View Post
    Hi All
    I want to ask question in matlab, Can I create if loop inside for loop such that if on condition of if hold then for loop must end, i.e How can we do the following
    For i = 1:2:10
    if mod(i,2)=0
    end
    else
    i
    end

    Best wishes
    The correct program should read:

    Code:
    for i=1:2:10
        if mod(i,2)==0
          break
        else 
          i
        end
    end
    Last edited by CaptainBlack; January 4th 2011 at 03:58 AM. Reason: added code block and indentation
    Follow Math Help Forum on Facebook and Google+

  3. #3
    Grand Panjandrum
    Joined
    Nov 2005
    From
    someplace
    Posts
    14,972
    Thanks
    4
    This has already been aswered in your last thread:

    >>help break

    CB
    Follow Math Help Forum on Facebook and Google+

Similar Math Help Forum Discussions

  1. Question in matlab
    Posted in the Math Software Forum
    Replies: 2
    Last Post: December 24th 2010, 12:32 PM
  2. matlab question.need help :(
    Posted in the Math Software Forum
    Replies: 0
    Last Post: October 7th 2009, 07:58 AM
  3. Matlab Question Help
    Posted in the Math Software Forum
    Replies: 6
    Last Post: September 20th 2009, 10:57 PM
  4. A Matlab Question
    Posted in the Math Software Forum
    Replies: 2
    Last Post: August 8th 2009, 01:02 AM
  5. Hello - Matlab question
    Posted in the Math Software Forum
    Replies: 1
    Last Post: May 3rd 2009, 11:59 PM

Search Tags


/mathhelpforum @mathhelpforum