The identifiers below are keywords, and may not be used as variable or function names:
Utility Functions | Variable Declaration | Function Definition | Control Statements | Iterating Structures | Classdef Structures | Execution Environment
__FILE__ | __LINE__ | break | case | catch | classdef | continue | do | else | elseif | end | end_try_catch | end_unwind_protect | endclassdef | endenumeration | endevents | endfor | endfunction | endif | endmethods | endparfor | endproperties | endswitch | endwhile | endenumeration | events | for | function | global | if | methods | otherwise | parfor | persistent | properties | return | switch | try | until | unwind_protect | unwind_protect_cleanup | while
The function iskeyword
can be used to quickly check whether an
identifier is reserved by Octave.
()
¶(name)
¶Return true if name is an Octave keyword.
If name is omitted, return a list of keywords.
var
¶Declare variables to have global scope.
global x; if (isempty (x)) x = 1; endif
See also: persistent.
var
¶Declare variables as persistent.
A variable that has been declared persistent within a function will retain its contents in memory between subsequent calls to the same function. The difference between persistent variables and global variables is that persistent variables are local in scope to a particular function and are not visible elsewhere.
See also: global.
outputs = function_name (input, …)
¶ function_name (input, …)
¶outputs = function_name
¶Begin a function body with name function_name
, with outputs as
results, and with inputs as parameters.
The function can later be invoked in Octave using the syntax
[output1, output2, ...] = function_name (input1, input2, ...)
See also: return.
Last element of an array or the end of any for
, parfor
,
if
, do
, while
, function
, switch
,
try
, or unwind_protect
block.
As an index of an array, the magic index "end"
refers to the
last valid entry in an indexing operation.
Example:
x = [ 1 2 3; 4 5 6 ]; x(1,end) ⇒ 3 x(end,1) ⇒ 4 x(end,end) ⇒ 6
Programming notes:
end
keyword cannot be used within subsref
,
subsasgn
, or substruct
for manual indexing operations.
end
in indexing expressions it
must be overloaded with a function definition such as:
function last_index = end (obj, end_dim, ndim_obj) if (end_dim == ndim_obj) last_index = prod (size (obj)(end_dim:ndim_obj)); else last_index = size (obj, end_dim); endif endfunction
For more information see Object Oriented Programming.
See also: for, parfor, if, do, while, function, switch, try, unwind_protect.
Return execution control immediately from a function or script to the calling code.
return
is used to stop executing code and exit an m-file immediately
rather than continuing until the end of the function or script is reached.
If the function or script was invoked directly, rather than from calling code in an m-file, then Octave returns to the command line.
See also: function.
(cond) … endif
¶(cond) … else … endif
¶(cond) … elseif (cond) … endif
¶(cond) … elseif (cond) … else … endif
¶Begin an if block.
The conditional cond is true if it is not empty and if all values are nonzero.
x = 1; if (x == 1) disp ("one"); elseif (x == 2) disp ("two"); else disp ("not one or two"); endif
See also: switch.
(cond)
¶Alternate conditional test for an if block.
The conditional cond is true if it is not empty and if all values are nonzero.
See if
for an example.
See also: if.
statement
¶Begin a switch block.
yesno = "yes"; switch (yesno) case {"Yes" "yes" "YES" "y" "Y"} value = 1; case {"No" "no" "NO" "n" "N"} value = 0; otherwise error ("invalid value"); endswitch
value
¶{value, …}
¶A case statement in a switch block.
Octave cases are exclusive and do not fall-through as do C-language cases. A
switch statement must have at least one case. See switch
for an
example.
See also: switch.
The default statement in a switch block which is executed when no other case statements match the input.
Begin a try-catch block.
If an error occurs within a try block, then the catch code will be run and
execution will proceed after the catch block (though it is often recommended to
use the lasterr
function to re-throw the error after cleanup is
completed).
See also: catch, unwind_protect.
Begin an unwind_protect block.
If an error occurs within the first part of an unwind_protect block the commands within the unwind_protect_cleanup block are executed before the error is thrown. If an error is not thrown, then the unwind_protect_cleanup block is still executed. In other words, the unwind_protect_cleanup code is guaranteed to execute regardless of success or failure in the unwind_protect block.
See also: unwind_protect_cleanup, try.
Begin the cleanup section of an unwind_protect block.
See also: unwind_protect.
Mark the end of an unwind_protect block.
See also: unwind_protect.
(cond)
¶Begin a while loop.
The conditional cond is true if it is not empty and if all values are nonzero.
i = 0; while (i < 10) i++ endwhile
Begin a do-until loop.
This differs from a while loop in that the body of the loop is executed at least once.
i = 0; do i++ until (i == 10)
(cond)
¶End a do-until loop.
The conditional cond is true if it is not empty and if all values are nonzero.
See do
for an example.
See also: do.
i = range
¶(i = range, maxproc)
¶Begin a for loop that may execute in parallel.
A parfor
loop has the same syntax as a for
loop. If your Octave
session has a parallel processing pool enabled, the iterations of the
parfor
loop will be executed in parallel across the pool’s workers.
Otherwise, parfor
will behave exactly as for
.
When operating in parallel mode, a parfor
loop’s iterations are not
guaranteed to occur sequentially, and there are additional restrictions about
the data access operations you can do inside the loop body.
Warning: parallel processing pools are currently unimplemented in
Octave; parfor
currently behaves exactly as a normal for
loop.
parfor i = 1:10 i endparfor
Exit the innermost enclosing do, while, or for loop.
Jump to the end of the innermost enclosing do, while, or for loop.
Begin a classdef block.
See also: properties, methods, events, enumeration.
Mark the beginning of a block of properties in a classdef definition. Note
that the function "properties"
is a function
that lists the properties of a classdef class or object.
See also: endproperties.
Mark the end of a properties block in a classdef definition.
See also: properties.
Mark the beginning of a block of methods in a classdef definition. Note that
the function "methods"
is a function that lists
the methods of a class or object.
See also: endmethods.
Begin an events block in a classdef definition.
Begin an enumeration block in a classdef definition.
Mark the end of an enumeration block in a classdef definition.
See also: enumeration.
When the lexer recognizes the "__FILE__"
keyword it returns a
character array containing the full name and path of the file that is being
executed. "__FILE__"
will return stdin
if called from the
command line.
See also: __LINE__.