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
Function rmfield - structure: The function rmfield eliminates a field from the structure. It returns a new structure with field eliminated, but does not modify the original st

Finding products by for loop: an illustration, when 5 is passed to be the value of the input argument n, the function will compute and return 1 + 2 + 3 + 4 + 5, or 15: >> s

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

. Generate the following signal, x(n)=1+cos((25*pi*n)/100),0 Compute the DTFT of x[n] for w=0:0.01:2*pi Plot the Real part, imaginary part, the amplitude and phas

printrectarea function: function call: printrectarea(length, width) function header: function printrectarea(len, wid)   In the function call, there are two argume

Algorithm for appex subfunction: The algorithm for appex subfunction is as shown:  Receives x & n as the input arguments.  Initializes a variable for running sum of t

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

Uses of Function handles: The Function handles can also be generated for functions other than anonymous functions, both built-in & user-defined functions. For illustration, th

Referring to and Showing Cell Array Elements and Attributes: Just as with the other vectors, we can refer to individual elements of the cell arrays. The only difference is tha

Example Exit modular program: In the illustration below, the user  Chose the Limit; -   Whenever prompted for n, entered the two invalid values before finally ente