if-else condition
It is similar to if condition but when the test expression in if condition fails, then statements in else condition are executed. Syntax :
if (condition) statements ... ... else statements ... ... end (endif can also be used)
Example :
MATLAB
% initializing variables variable1 and variable2 variable1 = 20; variable2 = 40; % check the if condition if variable1 == variable2, % if the condition is true this statement will execute disp( 'The variables are Equal' ); % if the condition is false else statement will execute else disp( 'The variables are Not Equal' ); %end the if-else statement end ; |
Output:
The variables are Not Equal
Loops (For and While) and Control Statements in Octave
Control statements are expressions used to control the execution and flow of the program based on the conditions provided in the statements. These structures are used to make a decision after assessing the variable. In this article, we’ll discuss control statements like the if statement, for and while loops with examples.
Contact Us