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
Illustration sorting vectors of structures: This function sorts the structures depend only on the price field. A more common function is shown next, that receives a string whi

Scaling:   change a row by multiplying it by a non-zero scalar sri →  ri For illustration, for the matrix:

Displaying expressions: The good-looking function will show such expressions by using exponents; for illustration, >> b = sym('x^2') b = x^2 >> pretty(b)

Function strncmp: The function strncmp compares only the first n characters in the strings and ignores the rest. The initial two arguments are strings to compare, and third ar

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

Interpolation and extrapolation: In most cases, it is desired to estimate values other than at the sampled data points. For illustration, we may want to estimate what the temp

Illustration of Matrix solutions: For illustration, consider the three equations below with 3unknowns x 1 ,x 2 , and x 3 : We can write this in the form Ax = b here A

Passing Structures to Functions: The whole structure can be passed to a function, or separate fields can be passed. For illustration, here are the two distinct versions of a f

Illustration of Preallocating a Vector: Illustration of calling the function: >> myveccumsum([5 9 4]) ans =     5  14  18 At the first time in the loop, outvec wil

ischar function: The ischar function return the logical true if an array is a character array, or logical false if not. >> vec = 'EK127'; >> ischar(vec) ans =