The function iskeyword can be used to check whether an identifier is
reserved by Octave.
tf = iskeyword (name) ¶keyword_list = iskeyword () ¶Return true if name is an Octave keyword.
If name is omitted, return a list of keywords.
Variable Declaration | Function Definition | Control Statements | Iterating Structures | Classdef Structures | Execution Environment
The identifiers below are keywords, and may not be used as variable or function names.
__FILE__ | __LINE__ | arguments | break | case | catch | classdef | continue | do | else | elseif | end | end_try_catch | end_unwind_protect | endarguments | endclassdef | endenumeration | endevents | endfor | endfunction | endif | endmethods | endparfor | endproperties | endswitch | endwhile | enumeration | events | for | function | global | if | methods | otherwise | parfor | persistent | properties | return | switch | try | until | unwind_protect | unwind_protect_cleanup | while
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.
[output1, …] = function_name (input1, …) ¶ function_name (input1, …) ¶output = 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.
The termination of a code block or the last element of an array.
The keyword end is used to terminate blocks of code begun with
for, parfor, if, do, while, function,
switch, try, or unwind_protect.
When using classdef (object-oriented) programming, the keyword terminates blocks
of code begun with classdef, properties, methods,
events, or enumeration.
As an index of an array, the magic index "end" refers to the last valid
entry in an indexing operation.
Examples:
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 requires
writing an overloaded function 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.
Begin a function arguments block.
Warning: Function arguments validation blocks are not yet implemented
in Octave. Use of the keyword arguments will cause the parser to emit a
warning, and may throw an error depending on the contents of the code in the
block.
Terminate a function arguments block.
Warning: Function arguments validation blocks are not yet implemented
in Octave. Use of the keyword arguments will cause the parser to emit a
warning, and may throw an error depending on the contents of the code in the
block.
See also: arguments.
(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 ¶{value1, …} ¶A case statement in a switch block.
The code associated with a case statement is executed if one of the
tests below succeeds given a switch argument statement and a
value of type:
statement == value
strcmp (statement, value)
eq (statement, value)eq function which performs ‘==’)
Programming Notes: 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 code in the catch
block will be run. 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.
exception_var ¶Begin the cleanup part of a try-catch block.
If exception_var is specified then a variable of that name will defined
in the scope of the catch block. The variable is a scalar struct with
fields identifier, message, and stack which describes
the error that was caught.
See also: try.
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.
Terminate 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 not a
keyword, but rather an ordinary function that lists the properties of a classdef
class or object.
See also: endproperties.
Terminate 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 not a keyword,
but rather an ordinary 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.
Terminate 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__.