MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn moreOpportunities for recent engineering grads.

Apply Today**New to MATLAB?**

Asked by preet
on 6 Apr 2013

i am changing my code of c language in to matlab .but its gives infinite loop in Matlab during use 'continue' statement?

what is the problem? is there any other alternate of 'continue' statement?

*No products are associated with this question.*

Answer by Friedrich
on 6 Apr 2013

Edited by Friedrich
on 6 Apr 2013

Accepted answer

Hi,

yes continue in MATLAB is the same as in C. However when I look at that while loop:

while j<=n if j==i continue; end

this can`t even work in C. If j == i you will hit an endless loop because j never changes. Maybe you are missing to increment j before the continue statement?

preet
on 6 Apr 2013

thanx for reply. but dear friedrich i already incremented j, problem is something else.

Cedric Wannaz
on 6 Apr 2013

No, the problem is precisely here. You increment `j` after the conditional statement, so your code is looping between the WHILE and the CONTINUE, without ever incrementing `j`. It would be the exact same in `C`, unless you had a `j++` in either condition.

## 4 Comments

## Jan Simon (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/70081#comment_141536

Without seeing the code, we cannot guess what's going on. Please, kpreet, think twice: Do you really think that a useful answer is possible based on this level of information?

## preet (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/70081#comment_141537

my code is too long dear...thats why i did not paste here.

## preet (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/70081#comment_141538

let me know both continue statements are same in matlab and c language

## preet (view profile)

Direct link to this comment:http://www.mathworks.com/matlabcentral/answers/70081#comment_141541

for i=istart:n

if distmin>dist2

. . . . .

end

end