| 
  • If you are citizen of an European Union member nation, you may not use this service unless you are at least 16 years old.

  • You already know Dokkio is an AI-powered assistant to organize & manage your digital files & messages. Very soon, Dokkio will support Outlook as well as One Drive. Check it out today!

View
 

Turing Reference - Selection Statement with Multiple Outcomes

Page history last edited by Steve Sweeney 10 years, 4 months ago

 

A selection statement, commonly referred to as an IF statement, lets you decision between one or more outcomes, or results.

 

A typical selection statement will have one outcome or two outcomes, but it is possible to account for many outcomes.

 

The first way to represent multiple outcomes is to used a nested IF statement.  The following code tries 3 conditions, which gives a total of 4 outcomes (the 4th outcome is for all conditions false).

 

if <condition1> then

   % do something because the condition is TRUE

   put "The first condition was true"

else

   if <condition2> then

      put "The second condition was true"

   else

      if <condition3> then

         put "The third condition was true"

      else

         put "None of the conditions were true, so I'm giving up"

      end if

   end if

end if

 

Turing provides a more condensed version of this code using a special structure known as an "else-if".  Here is the exact same code as above using the "else-if" structure:

 

if <condition1> then

   % do something because the condition is TRUE

   put "The first condition was true"

elsif <condition2> then

   put "The second condition was true"

elsif <condition3> then

   put "The third condition was true"

else

   put "None of the conditions were true, so I'm giving up"

end if

 

You may also wish to consider a decision with only one outcome, or a decision with multiple outcomes.

 

Comments (0)

You don't have permission to comment on this page.