MATLAB Answers

C Zeng

What is the difference of using ; after end?

Asked by C Zeng
on 14 Oct 2012

Hi, dear all,

For example, if I write a if loop, after end, what is the difference if I use ;?




No products are associated with this question.

2 Answers

Answer by Wayne King
on 14 Oct 2012
Edited by Wayne King
on 14 Oct 2012
 Accepted answer

None, you don't need a semi-colon after an end statement. Putting a semi-colon in or leaving one off do not generate mlint warnings.


Walter Roberson
on 7 Nov 2012

I think the notes I saw were in the cssm newsgroup. Most likely written by Bruno, or Jan.

C Zeng
on 7 Nov 2012

OK, but I think it is a minor issue for computation, because with or without ";" does not change a lot.

Walter Roberson
on 7 Nov 2012

The timing difference that comes to mind was on the order of a factor of 10 for the testcase that was used. As the internal mechanism that causes the issue is not well understood (at least not to us on the outside of Mathworks), it is not currently possible to predict whether the difference would scale with number of iterations or with work done in each iteration or if it was more or less a constant delay that could effectively be amortized.

Answer by Daniel
on 7 Nov 2012

I often add a semicolon or comma after statements like "end" where they are not strictly useful so that I can easily create single line commands. This is especially true when trying to answer questions on Answers

For example, you need a semicolons/commas to make the following work

for ii = 1:10, end;  ii

  1 Comment

C Zeng
on 7 Nov 2012

Makes sense.

Discover MakerZone

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

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!