Common Pseudocode Notations
Variables and Data Types
- DECLARE: Declare a variable (e.g., DECLARE x INTEGER)
- ASSIGN: Assign a value to a variable (e.g., x = 5)
Control Structures
- IF-THEN: Conditional statement (e.g., IF x > 5 THEN PRINT "x is greater than 5")
- IF-THEN-ELSE: Conditional statement with alternative action (e.g., IF x > 5 THEN PRINT "x is greater than 5" ELSE PRINT "x is less than or equal to 5")
- FOR LOOP: Iterate over a sequence (e.g., FOR i = 1 TO 5 DO PRINT i)
- WHILE LOOP: Iterate while a condition is true (e.g., WHILE x < 5 DO x = x + 1)
Functions and Procedures
- FUNCTION: Define a reusable block of code (e.g., FUNCTION calculateArea(length, width))
- PROCEDURE: Define a block of code that performs a specific task (e.g., PROCEDURE printHello)
Input/Output
- READ: Read input from a user or system (e.g., READ userInput)
- PRINT: Output data to a user or system (e.g., PRINT "Hello, world!")
Operators
- ARITHMETIC OPERATORS: +, -, *, /, MOD (modulus)
- COMPARISON OPERATORS: =, ≠, <, >, ≤, ≥
- LOGICAL OPERATORS: AND, OR, NOT
Example
IF user_age > 18 THEN
PRINT "You are an adult."
ELSE
PRINT "You are not an adult."
END IF
No comments:
Post a Comment