Open In App

Comments in Octave GNU

Improve
Improve
Like Article
Like
Save
Share
Report

Octave is open-source, free available for many of the platforms. It is a high-level language. It comes up with a text interface along with an experimental graphical interface. It is also used for various Machine Learning algorithms for solving various numeric problems. You can say that it is similar to MATLAB but slower than MATLAB.

Comments are generic English sentences, mostly written in a program to explain what it does or what a piece of code is supposed to do. More specifically, information that programmer should be concerned with and it has nothing to do with the logic of the code. They are completely ignored by the compiler and are thus never reflected on to the input.

In Octave comments are of two types:

  • Single-line Comments
  • Block Comments

Single-line Comments

Single-line comments are comments that require only one line. They are usually drafted to explain what a single line of code does or what it is supposed to produce so that it can help someone referring to the source code. In octave to make a line comment just put a ‘#’ or ‘%’ in front of that line.

Syntax :

# comment statement 
% comment statement 

Example :




char1 = '#';
printf("Below is the comment using %c\n", char1);
# this is a comment
  
char2 = '%';
printf("Below is the comment using %c\n", char2);
% this is also a comment


Output :

Below is the comment using #
Below is the comment using %

Block Comments

In octave to make a block comment just put a ‘#{‘ or ‘%{‘ in the starting of the block and ‘#}’ or ‘%}’ at the end of the block.

Syntax :

#{ 
this is
 a block
 comment
#}

%{ 
this is  
 a block 
 comment
%} 

Example :




char1 = '#';
printf("Below is the block comment using %c\n", char1);
#{
this is a
 comment
 using #
 #}
  
char2 = '%';
printf("Below is the block comment using %c\n", char2);
%{
this is a
 comment
 using %
 %}


Output :

Below is the block comment using #
Below is the block comment using %

Last Updated : 01 Aug, 2020
Like Article
Save Article
Previous
Next
Share your thoughts in the comments
Similar Reads