TestingDocs.com
Software Testing website
  • Automation
    • Selenium
    • JBehave Framework
  • Tutorials
    • MySQL Tutorials
    • Testlink
    • Maven
    • Git
  • IDEs
    • IntelliJ IDEA
    • Eclipse
  • Flowcharts
    • Flowgorithm
    • Raptor
  • About

Octave

Octave for Statement

Overview

In this tutorial, we will learn about Octave for Statement.
The for statement is a loop statement.

Octave for Statement

The for statement is used to execute a set of statements for a fixed number of iterations. for loop is a definite loop. We can use this loop if we know the number of iterations beforehand.

The syntax of the for statement is:

for var = expression
         for_loop_body
endfor

or

for var = expression
         for_loop_body
end

For better readability we can use the endfor to end the loop.

Simple Example

% Sample Octave Script
% For Loop Demo
% Octave Tutorials – www.TestingDocs.com

%Clear environment
clc;
clear;

% for Loop to print 1 -> 10
for n= 1 : 10
     fprintf(‘For Loop Iteration = %d \n’,n);
endfor

The for loop runs for ten iterations and prints the iteration number.

 

Octave For Statement

Output

For Loop Output

Nested for loops

In Octave, it is possible to write a nested for loop, that is, a for loop within another for loop.

For example, two nested for loops.

for i = 1:n
      for j = 1:m
     % Inner for loop statements
     end % Inner for loop
     % Some outer for loop statements
end % Outer for loop

—

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

Related Posts

Octave Package List

Octave /

Install Octave Packages on Linux

Octave /

Octave User defined Function Example

octave command line linux

Octave /

Octave Command line on Ubuntu

Hello World in Octave

Octave /

Hello World in Octave

Octave /

Octave plot example of function y=x^2

‹ Octave while Statement› Octave break Statement

Recent Posts

  • MS Access Data Types
  • Install RAPTOR Avalonia on CentOS
  • Download RAPTOR Avalonia Edition on Windows
  • npm doctor command
  • Build & Run CLion Project
  • Create New CLion C Project on Windows
  • Configure CLion Toolchains on Windows
  • Launch CLion IDE on Windows
  • Activate CLion IDE
  • CLion IDE for C/C++ Development

Back to Top

Links

  • Contact
  • Privacy Policy
  • Cookie Policy

www.TestingDocs.com

Go to mobile version