MATLAB Functions Help Desk

end

Purpose

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

Syntax

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

Description

  1. 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.
  2. 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

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       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



[ Previous | Help Desk | Next ]