Resources | Subject Notes | Computer Science
Structured programming is a fundamental paradigm in computer science that emphasizes the use of control flow structures to create well-organized and readable code. It avoids the use of unstructured constructs like `GOTO` statements, which can lead to complex and difficult-to-debug programs. The core principles of structured programming are sequences, selections (if-then-else), and iterations (loops).
PseudoCode is an informal way of describing the logic of a program. It uses a combination of natural language and programming-like syntax to outline the steps involved. It's not intended to be directly executed by a computer but serves as a blueprint for translating into a specific programming language.
Construct | Description | Example |
---|---|---|
Assignment | Assigns a value to a variable. | x = 10 |
Conditional Statement (if-then-else) | Executes different blocks of code based on a condition. |
if (condition) then
// Code to execute if condition is true
else
// Code to execute if condition is false
end if
|
Loop (For loop) | Repeats a block of code a specified number of times. |
for i = start to end do
// Code to execute in each iteration
end for
|
Loop (While loop) | Repeats a block of code as long as a condition is true. |
while (condition) do
// Code to execute while condition is true
end while
|
Function/Procedure Definition | Defines a reusable block of code. |
function calculateArea(length, width)
area = length * width
return area
end function
|
To write efficient pseudoCode, consider the following:
Here's an example of pseudoCode to calculate the area of a rectangle:
function calculateRectangleArea(length, width)
area = length * width
return area
end function
// Main program
get length
get width
rectangleArea = calculateRectangleArea(length, width)
display "The area of the rectangle is: " + rectangleArea
Practice writing pseudoCode for various problems. Start with simple tasks and gradually increase the complexity. This will help you develop a strong understanding of structured programming principles.