Question:

Tell me the if-then-else function with a healthy example?

by  |  earlier

0 LIKES UnLike

it is related to if function

 Tags:

   Report

3 ANSWERS


  1. what does this have to do with Special Ed? please learn what special ed is, and how to use yahoo answers properly

    thank you


  2. "if" allows you to execute a piece of code if a condition is found to return true.  "else" allows a piece of code to be executed if condition is false.

    syntax (formatting) depends on the programming language you are using:

    if (condition is true)

    then ..... "code to execute if condition is true"

    else.... "code to execute if condition is false"

    Example

    If we want a looping function that reduces x by 1 each cycle while it is 0 or greater.

    if (x<0) then x=0

    else x = x-1

    which programming language are you using?

  3. This can be described as:

    Conditionally executing statement (or a group of statements), depending on the value of an expression.

    The IF relates to a particular condition to be assessed.

    The THEN describes the action to be taken if the condition is true,

    The ELSE describes the action to be taken if the condition is not true (false).

    IF THEN ELSE can be used in a number situations. Eg

    In Spreadsheeting:

    Excel uses the IF function (strickly speaking the THEN ELSE is not specifically mentioned but the Excel IF function performs the same actions.

    In industrial process controlling.

    Eg

    IF fluid level in vat A is at X, THEN close inlet valve Y, ELSE open inlet valve Y.

    In programming languages etc.

    IF (x > 0) THEN

       WRITE(*,*)  'A'

    ELSE

       WRITE(*,*)  'B'

    Can be nested to examine a number of conditions in one statement.

    That is: IF-THEN-(IF-THEN-ELSE)

    So...

    IF A3="Spring", THEN C3="Spring", ELSE="".

    Can become...

    IF A3="Spring", THEN C3="Spring", (IF B3="Summer", THEN B3="Spring Summer" ELSE="".)

    Another nested example in programming (uses END IF extension to indictate end of each IF statement):

    IF (x > 0) THEN

       WRITE(*,*)  '+'

    ELSE

       IF (x < 0) THEN

          WRITE(*,*)  '-'

       ELSE

          WRITE(*,*)  '0'

       END IF

    END IF

Question Stats

Latest activity: earlier.
This question has 3 answers.

BECOME A GUIDE

Share your knowledge and help people by answering questions.
Unanswered Questions