MATLAB Function Reference
  Go to function:
    Search    Help Desk 
end    Examples   See Also

Terminate for, while, switch, try, and if statements or indicate last index

Syntax

while expression            % (or if, for, or try)
B = A(index:end,index)

Description

end is used to terminate for, while, switch, try, and if statements. Without an end statement, for, while, switch, try, and if wait for further input. Each end is paired with the closest previous unpaired for, while, switch, try, or if and serves to delimit its scope.
The 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. Examples of this use are X(3:end) and X(1,1:2:end-1). When using end to grow an array, as in X(end+1)=5, make sure X exists first.

Examples

This example shows end used with for and if. Indentation provides easier readability.

Here, end is used in an indexing expression:

In this example, B is a 1-by-3 vector equal to [A(5,2) A(5,3) A(5,4)].

See Also

break       Terminate execution of for or while loop

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

try         Begin try block

while       Repeat statements an indefinite number of times



[ Previous | Help Desk | Next ]