Use of nested if-else statements, MATLAB in Engineering

Use of Nested if-else statements:

By using the nested if-else to select from among the three possibilities, not all the conditions should be tested. In this situation, if x is less than -1, the statement is assign 1 to y is then executed, and the if-else statement is done so no other conditions are tested. If, though, x is not less than -1, then the else clause is executed. When the else clause is executed, then we know that x is greater than or equal to -1 so that section does not require to be tested. Rather than that, there are only two remaining possibilities: either x is less than or equal to 2, or it is bigger than 2. An if-else statement is used to select between those two possibilities. Therefore, the action of the else clause was the other if-else statement. Though it is long, this is one if-else statement, and a nested if-else statement. The actions are indented to represent the structure.

Nesting if-else statements in such a way that it can be used to select from among three, four, five, or more options-the possibilities are practically endless!

This is really an illustration of a particular type of nested if-else known as cascading if-else statement. In this category of nested if-else statement, the conditions and actions cascade in the stair-like pattern.

 

 

Posted Date: 10/19/2012 3:21:33 AM | Location : United States







Related Discussions:- Use of nested if-else statements, Assignment Help, Ask Question on Use of nested if-else statements, Get Answer, Expert's Help, Use of nested if-else statements Discussions

Write discussion on Use of nested if-else statements
Your posts are moderated
Related Questions
Evaluating a string: The function eval is used to compute a string as a function. For illustration, below is the string 'plot(x)'is interpreted to be a call to plot the functi

Square Matrices: If a matrix has similar number of rows and columns, for illustration, if m == n, the matrix is square matrix. The definitions which follow in this part apply

Vector operations: As vectors are special cases of matrices, the matrix operations elaborated (addition, subtraction, multiplication, scalar multiplication, transpose) work on

Simplification Functions: There are numerous functions which work with expressions, and simplify the terms. Not all the expressions can be simplified, but the simplify functio

Built-in colormaps: The MATLAB has numerous built-in colormaps which are named; the reference page on colormap shows them. Calling the function colormap without passing any ar

Help command: The help command is used with the script rectarea, the function readlenwid, and the major function printrectarea. To see the first comment in the subfunction, as

Tracing of Square matrices: The trace of a square matrix is the addition of all the elements on the diagonal. For illustration, for the preceding matrix it is 1 + 6 + 11 + 16,

Reading from a Mat-File: The load function is used to read from various types of files. As with save function, by default the file will be supposed to be a MAT-file, and load

Example of modular program: In a modular program, there would be one main script which calls three separate functions to complete these tasks: A function to prompt an us

Example of Interpolation and extrapolation: The MATLAB has a function to do this, known as polyfit. The function polyfit finds the coefficients of the polynomial of the partic