When designing software, programmers rarely write code in a single, straight line from top to bottom. Instead, they use logic to make decisions and repeat tasks efficiently. Before translating logic into a specific programming language like Python or C++, developers use pseudo code—a simplified, human-readable way of expressing algorithms. This article explores the fundamental control structures that allow programs to handle multiple choices and repetitive data processing.
The Case Control Structure
In many programs, you need to perform different actions based on the value of a single variable. While you could use a long series of nested IF statements, this can quickly become messy and difficult to read.
The case control structure provides a cleaner alternative. It allows you to list multiple possible values for a variable and assign a specific action to each one. In pseudo code, this is typically identified by the keywords CASE OF and ENDCASE.
Example: Calculating Sales Tax Consider a scenario where different tax codes determine the sales tax rate:
BEGIN
Read/Process_customer_record
CASE OF tax_code
11 : sales_tax = 0
22 : sales_tax = purch_amt * 0.03
33 : sales_tax = purch_amt * 0.05
44 : sales_tax = purch_amt * 0.07
ENDCASE
total_amt = purch_amt + sales_tax
Print cust_name, purch_amt, sales_tax, total_amt
END
Repetition Control Structures
Most real-world programs require the same logic to be applied to many different sets of data. To avoid writing the same code hundreds of times, we use repetition control structures (also known as loops).
The type of loop you choose depends entirely on where the decision to repeat is made. There are three primary categories:
Keep reading for free.
Create an account to finish this reading and make it part of your study routine.
Continue reading freeAlready have an account? Log in
Updated