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.

On this post

## 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
continue
%code inside for-end will not work
end
x(y)= log10(x(y))
%mathematical code that converts to log
end
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.

## Conclusion

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