MATLAB Functions | Help Desk |
end
Terminatefor
, while
, switch
, and if
statements or indicate last index
while
expression %
(or if
or for
)
statements
end
B = A(
index
:end,
index
)
end
is used to terminate for
, while
, switch
, and if
statements. Without an end
statement, for
, while
, switch
, and if
wait for further input. Each end
is paired with the closest previous unpaired for
, while
, switch
, or if
and serves to delimit its scope.
end
command also serves as the last index in an indexing expression. In that context, end = (size(x,k))
when used as part of the kth index.
end
used with for
and if
. Indentation provides easier readability.
for i = 1:n if a(i) == 0 a(i) = a(i) + 2; end endHere,
end
is used in an indexing expression:
A = rand(5,4) B = A(end,2:end)In this example,
B
is a 1-by-3 vector equal to [A(5,2) A(5,3) A(5,4)]
.
break
Break out of flow control structures
for
Repeat statements a specific number of times
if
Conditionally execute statements
return
Return to the invoking function
switch
Switch among several cases based on expression
while
Repeat statements an indefinite number of times