Is It Okay to Add Semicolons After Every Expression?
Take, for example, this piece of code which adds semicolons even when there is no output to suppress:
clear;
clc;
x = 1:10;
y = (x+1).^2;
plot(1,y(1),"r*");
hold on;
for idx = 2:10
plot(idx,y(idx),"r*");
end
plot(x,y);
And this code which only includes semicolons when needed:
clear
clc
x = 1:10;
y = (x+1).^2;
plot(1,y(1),"r*")
hold on
for idx = 2:10
plot(idx,y(idx),"r*")
end
plot(x,y)
(These are just examples.) Is adding semicolons to every expression (the first example) wrong in any way?
It’s just that when not using the editor you are not told if there is output to suppress, so I thought it would just be easier to use semicolons everywhere instead of trying to remember or guess where they are needed. So is it syntactically/traditionally/etc wrong in any way?Take, for example, this piece of code which adds semicolons even when there is no output to suppress:
clear;
clc;
x = 1:10;
y = (x+1).^2;
plot(1,y(1),"r*");
hold on;
for idx = 2:10
plot(idx,y(idx),"r*");
end
plot(x,y);
And this code which only includes semicolons when needed:
clear
clc
x = 1:10;
y = (x+1).^2;
plot(1,y(1),"r*")
hold on
for idx = 2:10
plot(idx,y(idx),"r*")
end
plot(x,y)
(These are just examples.) Is adding semicolons to every expression (the first example) wrong in any way?
It’s just that when not using the editor you are not told if there is output to suppress, so I thought it would just be easier to use semicolons everywhere instead of trying to remember or guess where they are needed. So is it syntactically/traditionally/etc wrong in any way? Take, for example, this piece of code which adds semicolons even when there is no output to suppress:
clear;
clc;
x = 1:10;
y = (x+1).^2;
plot(1,y(1),"r*");
hold on;
for idx = 2:10
plot(idx,y(idx),"r*");
end
plot(x,y);
And this code which only includes semicolons when needed:
clear
clc
x = 1:10;
y = (x+1).^2;
plot(1,y(1),"r*")
hold on
for idx = 2:10
plot(idx,y(idx),"r*")
end
plot(x,y)
(These are just examples.) Is adding semicolons to every expression (the first example) wrong in any way?
It’s just that when not using the editor you are not told if there is output to suppress, so I thought it would just be easier to use semicolons everywhere instead of trying to remember or guess where they are needed. So is it syntactically/traditionally/etc wrong in any way? syntax, semicolons, text file MATLAB Answers — New Questions