An action in a single alternative decision structure is performed only when the condition is true.

Chapter 4 Programming
4.1
A decision structure allows a program to perform actions only under certain conditions – also known as selection structures. In its simplest form a specific action is performed only if a certain condition exists. If the condition does not exist the action is not performed.
Single alternative decision structure – because it provides only one alternative path of execution. If the condition In the diamond symbol is true we take the alternative path. Otherwise we exit the structure.
Writing a Decision Structure in Pseudocode
If condition Then Statement Statement Statement
End If

Boolean Expressions and Relational Operators
Booleans Expressions – expressions that can be evaluated as either true or false. Typically is formed with a relational operator. A relational operator determines where a specific relationship exists between two values.

Checkpoint
4.1 What is a control structure?
A logical design that controls the order in which a set of statements executes.
4.2 What is a decision structure?
A logical design that can execute only under certain circumstances
4.3 What is a single alternative decision structure?
Design structure that provides only one path of execution. If the condition in the diamond symbol is true, we take the alternative path. Otherwise, we exit the structure.
4.4 What is a Boolean Expression?
Expressions that can be evaluated as either true or false.
4.5 What types of relationships between values can you test with relational operators?
> Greater than, < Less Than, >= Greater than or equal to, <= Less than or equal to, == Equal to, != Not equal to
4.6 Write a pseudocode If-Then statement that assigns 0 to x if y is equal to 20.
If y=20 Set 0 =x
End If
4.7 Write a pseducode If-Then statement that assigns 0.2 to commission if sales is greater than or equal to 10,000.
If sales >=10,000 Set commission =0.2
End I
A dual alternative decision structure will execute one group of statements if its Boolean expression is true, or another group if its Boolean expression is false.

Dual alternative decision structure – has two possible paths of execution – one path is taken if a condition is true and other path is taken if the condition is false.
In Pseudocode we write a dual alternative structure as an If-Then-Else statement.
If condition Then Statement Statement Etc.
Else
Statement Statement Etc.
End If
In general format the condition is any Boolean expression. If the expression is true, the statements that appear next are executed up to the line that reads Else. If the expression is false the statements that appear between Else and End

Checkpoint
4.8 How does a dual alternative structure work?
One path is taken if the condition is true if it is false the other path Is taken
4.9 What statement do you use in pseudocode to write a dual alternative decision structure?
If-Then-Else statement
4.10 When you write an If-Then-Else statement, under what circumstances do the statements that appear between Else and End If execute?
When the statement is false

4.3 Comparing Strings
Most programming languages allow you to compare strings. This allows you to create decision structures that test the value of a string.

Checkpoint
4.11
If the following pseudocode were an actual program what would it display? z Is not less than a
4.12
S1
S2

4.4 Nested Decision Structures
To test more than one condition, a decision structure can be nested inside another decision structure.

The If-Then-Else If Statement
IF condition_1 Then Statement Statement Etc.
Else If condition_2 Then Statement Statement Etc.

Insert as many Else If clauses as necessary
Else
Statement Statement Etc.
End If

Checkpoint
4.13 How does a dual alternative structure work?
To qualify two conditions must exist. If the first condition is true we need to test the

  • School Penn Foster College
  • Course Title COMPUTER S csc105
  • Pages 25
  • Ratings 100% (1) 1 out of 1 people found this document helpful

This preview shows page 1 - 4 out of 25 pages.

Checkpoint Questions4.1 What is a control structure?

Get answer to your question and much more

4.2 What is a decision structure?

Get answer to your question and much more

4.3 What is a single alternative decision structure?

Get answer to your question and much more

4.4 What is a Boolean expression?

Get answer to your question and much more

4.5 What types of relationships between values can you test with relational operators?

Get answer to your question and much more

4.7 Write a pseudocodeIf-Thenstatement that assigns 0.2 tocommissionifsalesis greater thanor equal to 10,000.

Get answer to your question and much more

Display “Commission has been applied”

Get answer to your question and much more

4.8 How does a dual alternative decision structure work?

Get answer to your question and much more

4.9 What statement do you use in pseudocode to write a dual alternative decision structure?

Get answer to your question and much more

4.10 When you write anIf-Then-Elsestatement, under what circumstances do the statements thatappear betweenElseandEnd Ifexecute?

Get answer to your question and much more

4.11 If the following pseudocode were an actual program, what would it display?Program:If “z” < “a” ThenDisplay “z is less than a.”ElseDisplay “z is not less than a.”End IfProgram Output:z is not less than a.4.12 If the following pseudocode were an actual program, what would it display?Program:Declare String s1 = “New York”Declare String s2 = “Boston”If s1 > s2 ThenDisplay s2Display s1ElseDisplay s1

Display s2End IfProgram Output:s1s24.13 How does a dual alternative decision structure work?

Get answer to your question and much more

4.14 What statement do you use in pseudocode to write a dual alternative decision structure?

Get answer to your question and much more

4.15 When you write anIf-Then-Elsestatement, under what circumstances do the statements thatappear between theElse Clauseand theEnd Ifclause execute?

Upload your study docs or become a

Course Hero member to access this document

Upload your study docs or become a

Course Hero member to access this document

End of preview. Want to read all 25 pages?

Upload your study docs or become a

Course Hero member to access this document

Tags

Expression, relational operator, Switch statement

Which structure determines the order in which a set of statements executes?

A control structure is a logical design that controls the order in which a set of statements execute.

Which of the following is the correct If clause to use to determine whether choice is other than 10?

Review of Python Chapter 2.

What is the structure that causes a statement or a set of statements to execute repeatedly?

A repetition structure causes a statement or set of statements to execute repeatedly. Repetition structures are used to perform the same task over and over. A condition-controlled loop uses a Boolean (true/false) condition to control the number of times that it repeats.

When you write an if then else statement Under what circumstances do the statements that appear between the else clause and the end if clause execute?

In an If-Then-Else statement, the statements between Else and End If would execute only if the condition for the If portion did not evaluate as true. See the answer to 4.10 for examples.