Site icon TestingDocs.com

Octave break Statement

Overview

In this tutorial, we will learn about the Octave break Statement. We can use the break statement within the body of a loop.

Octave break statement

The break statement jumps the control out of the innermost loop that encloses the statement.

When Octave encounters the break statement, it breaks out of the loop. The statement that is immediately after the loop will be executed. We can use this statement in the loop to check special conditions and can skip the loop altogether.

Example

% Break Statement Demo 
% Octave Tutorials - www.TestingDocs.com

i = 0;

while (true) 

disp(i);

i++;

if (i > 5) 

  break; % Quit the loop if i > 5

endif

endwhile

 

Output

>> breakDemo

0
1
2
3
4
5

In the example, the break statement is used to quit the loop when the variable is greater than 5.

 

To skip the current iteration of the loop, we can use the continue statement.

https://www.testingdocs.com/octave-continue-statement/

Octave Tutorials

Octave Tutorial on this website can be found at:
https://www.testingdocs.com/octave-tutorial/

More information on Octave can be found on the official website:
https://www.gnu.org/software/octave/index

Exit mobile version