Home » All Programs » ‘continue’ Command In MatLab Programming

‘continue’ Command In MatLab Programming

To halt an program that is wrote in MatLab, you can use the break command by using a condition query with if-else. Also there is an another command is avaliable in Matlab that you can use to go on to other portions of code, without doing anything at that step where this command is used. This is ‘continue’ command. In here, we explain the use of ‘continue’ command in Matlab with a very basic example.

How To Use ‘continue’ In MatLab?

Take a look at the below example to understand the use of ‘continue’ in Matlab programming.

>> x=[ 7 6 5 1 -6 78 6];
    for y = 1:length(x)
        if x(y) <= 0
 %code inside for-end will not work
     x(y)= log10(x(y))
 %mathematical code that converts to log

x =

    0.8451    6.0000    5.0000    1.0000   -6.0000   78.0000    6.0000

x =

    0.8451    0.7782    5.0000    1.0000   -6.0000   78.0000    6.0000

x =

    0.8451    0.7782    0.6990    1.0000   -6.0000   78.0000    6.0000

x =

    0.8451    0.7782    0.6990         0   -6.0000   78.0000    6.0000

x =

    0.8451    0.7782    0.6990         0   -6.0000    1.8921    6.0000

x =

    0.8451    0.7782    0.6990         0   -6.0000    1.8921    0.7782


The very basic example above about the use of ‘continue’ in Matlab programming, we used the ‘continue’ inside ‘if-else’ query. In general, ‘continue’ is used inside ‘if-else’.

As you see above, we defined the vector ‘x’ which has 7 elements inside it, and one of these elements is ‘-6’.

So, we want to obtain a new vector which includes the elements which are bigger than zero,obtained by the elements of ‘x’, by taking their logarithms in 10 basis.

To do it, we need to count all the elements of vector ‘x’ by using ‘for-end’ loop to give the new values to these elements. To do it, we obtained the ‘for-end’ loop which has the number of loops equals to the number of elemements of ‘x’. We did this by using ‘length()’ command.

We placed the ‘if-else’ inside ‘for-end’, that the code inside ‘for-end’ will not work if the value of element ‘x’ is smaller than zero. Otherwise, in each loop inside ‘for-end’ will convert the elements of ‘x’ into logaritmic values.


So, the use of ‘continue’ command is like above in Matlab. If you want further examples about ‘continue’ command, please inform us at the comments.

YOU CAN LEARN MatLab IN MECHANICAL BASE; Click And Start To Learn MatLab!

Do not forget to leave your comments and questions about the use of ‘continue’ command in Matlab programming below.

Your precious feedbacks are very important for us.


Leave a Reply

Your email address will not be published. Required fields are marked *


leave feedback ?

( For the post )



We are always open to your feedback to improve ourselves and the quality of our content! If you have any suggestions, thoughts, or criticism, please let us know. We are trying to improve our blog with constructive feedback. We are aware of how valuable your feedback is for our future development, and we will carefully read all your comments. Thank you in advance!