Illustration of if - else statement, MATLAB in Engineering

Illustration of if - else statement:

The one application of an if-else statement is to check for errors in the inputs to a script. For illustration, a former script prompted the user for a radius, and then used that to compute the area of a circle. Though, it did not check to make sure that the radius be valid (example, a positive number). Here is a modified script which checks the radius:

1653_Illustrations of if statement1.png

Illustrations of running this script whenever the user enters invalid and then valid radii are shown here:

>> checkradius

Please enter the radius: -4

Sorry; -4.00 is not a valid radius

>> checkradius

Please enter the radius: 5.5

For a circle with radius of 5.50, the area becomes 95.03

The if-else statement in this illustration selects between two actions: printing an error message, or really using the radius to compute the area, and then printing out the result. Note that the action of the if clause is a single statement, while the action of the else clause is a group of three statements.

Posted Date: 10/19/2012 3:20:00 AM | Location : United States







Related Discussions:- Illustration of if - else statement, Assignment Help, Ask Question on Illustration of if - else statement, Get Answer, Expert's Help, Illustration of if - else statement Discussions

Write discussion on Illustration of if - else statement
Your posts are moderated
Related Questions
For Loops which do not use an iterator Variable in the action: In all the illustrations that we seen so far, the value of the loop variable has been used in same way in the ac

Illustration of Vectors of structures: In this illustration, the packages are vector which has three elements. It is shown as a column vector. Each and every element is a stru

Indexing into Vectors of structures: Frequently, when the data structure is a vector of structures, it is essential to iterate through the vector in order by various fields. F

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

Program of passing arguments to functions: This was an illustration of a function which did not receive any input arguments nor did it return any output arguments; it easily a

Illustration of symbolic variable: When, on the other hand, z is a symbolic variable to start with, quotes are not required around the expression, and the words are automatica

Interchange rows : for illustration interchanging rows ri and rj is written as

Illustration of Sorting strings: To sort on the rows rather than second dimension should be specified. >> sort(words,2) ans = Hello Hdowy Hi Gbdeo

Comparing strings: There are few functions which compare strings and return logical true when they are equivalent or logical false when not. The function strcmp compares the s

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