Object-Oriented Programming (From Problem Solving to JAVA) (Charles River Media Programming)

7.7 Summary

The selection design structure, also known as alternation, is very useful to construct algorithms for simple problems. The two statements in pseudocode explained are the if and case statements. The first one is applied when there are two possible paths in the algorithm, depending on how the condition evaluates. The case statement is applied when the value of a variable is tested, and there are multiple possible values; one path is used for every value selected.

The condition in the if statement consists of a Boolean expression, which evaluates to a truth-value (true or false). It is constructed with relational operators between two data items. Conditions that are more complex are formed from simple ones using logical operators.

The KJP language (as other programming languages) includes equivalent statements for the selection structures.

Категории