Site icon TestingDocs.com

Octave Increment & Decrement operators

Overview

In this tutorial, we will learn about Octave Increment & Decrement Operator. The increment and decrement in Octave are unary operators. They take and operate on a single operand.

Increment Operator

The increment operator is used to increment the variable value by 1. We can apply the operator before or after the operand.

Pre-increment the value of the variable is increased and then used in the expression.

For example;

++x  is equivalent to

x = x + 1

Post-increment the present value of the variable is used in the expression and then the value of the variable is increased.

x++

For example, if the variable x =7 then the expression that has x++ uses the value 7 and then increments the value of x variable to 8.

Example

>> i = 10;
>> ++i % Pre-increment operator
ans = 11
>> i
i = 11
>> i++ % Post-increment operator
ans = 11
>> i
i = 12

Decrement Operator

The decrement operator is used to decrement the variable value by 1. We can apply the operator before or after the operand.

For example;

–x  is equivalent to

x = x – 1

Example

>> i = 10;
>> –i % Pre-decrement
ans = 9
>> i
i = 9
>> i– % Post-decrement
ans = 9
>> i
i = 8

 

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