Learn Computer Science

My initiative

The reason I post my computer science notes is to help others learn computer science more easily. I used to struggle with the Pseudocode rules and details. If you have any problems, please contact me at my email.

Pseudocode

General Rules

Identifiers

  • Meaningful Name: describe variants well(to be simple, longer :D)

Key Words

  • not using existing key words!!
  • Using comments as more as you can(//)

Naming Conventions

  • Camel Case or ‘_’

Data

Normal Data Type:

  • INTEGER
  • REAL (float): real number
  • CHAR: One character
  • STRING
  • BOOLEAN: TRUE or FALSE.
  • DATE: format is dd/mm/yyyy
  • ARRAY: a list
  • FILE: a single file
  • RECORD: using 1 id to include multiple data type

Abstract Data Type:

Definition: A collection of data and a set of operations on those data

  • STACK:First in Last out
    1. push
    1. pop
  • QUEUE:First in First out
    1. enqueue
    1. dequeue
  • LINKED LIST: like a pointer-oriented array

Declare

Constants

1
CONSTANT HourlyRate = 6.5

Variables

1
DECLARE <variable_name1> : <datatype>, <variable_name2> : <datatype>

Assignments

1
<variable_name> ← <value>

Assign Date

1
<variable_name> ← SETDATE(<day>, <month>, <year>)

Control

IF Statements (Nested, Maximum of three times)

  • IF:
1
2
3
4
5
6
IF <condition>
THEN
<do>
ELSE (optional)
<do>
ENDIF
  • or(I think this is better)
1
2
3
4
5
IF <condition> THEN
<do>
ELSE (optional)
<do>
ENDIF
  • CASE:
1
2
3
4
5
6
CASE OF <identifiers>
<value 1>: <do>
<value 2>, <value3>: <do>
<value 4> TO <value5>: <do>
OTHERWISE: <do>
ENDCASE

Identifiers

  • Starts with a letter, supports only standard English characters, numbers + letters, case sensitive, includes underscores (_).

Loops

Q:

Justify why one loop structure may be better suited to solve a problem than the others

A:

  1. Count-Controlled Loop: Count is known, easy to write and read.
  2. Pre-condition loop: Count is unknown, pre-condition check, dynamically stops.
  3. Post-condition loop: Count is unknown, at least once, very user-friendly.

Count-Controlled Loop

  • FOR:
1
2
3
4
FOR <identifier> ← <value1> TO <value2>
<do>
...
NEXT <identifier>

While Loops

  • WHILE Loop:Pre-condition loop
1
2
3
4
WHILE <statement>
<do>
...
ENDWHILE

Repeat-Until Loops

  • REPEAT UNTIL Loop:Post-condition loop
    1
    2
    3
    4
    REPEAT
    <do>
    ...
    UNTIL <statement>

IO control

Input

1
INPUT <variable_name>

Output

1
OUTPUT <variable_name>

File

Open file:

1
OPENFILE "<filename>" FOR <filemode> 

file mode: READ, WRITE, APPEND

note that APPEND mode is writing after the origin content, WRITE mode will remove all existing content.

Close file

1
CLOSEFILE "<filename>"

Read file

  • Read a file (read a line into the variable )
1
READFILE "<filename>", <variable_name>

Write file

  • Overwrite content
1
WRITEFILE "<filename>", <data>

EOF

  • Check whether the file is end
1
EOF ("<filename>")

Function

If the question specified that the variable is global, you don’t have to import yourself

Procedures:

  • 定义
1
2
3
PROCEDURE <precedure_name> ((Default is BYVAL)<param1>:<datatype>, <param1>:<datatype>)
<do>
ENDPROCEDURE
  • Usage
1
CALL <procedure_name> (<param1>, <param2>)

By reference

  • define
1
2
3
PROCEDURE <precedure_name> (<param1>:<datatype>, BYREF <param1>:<datatype>)
<do>
ENDPROCEDURE
  • Definition
1
2
3
4
FUNCTION <function_name> (<param1>:<datatype>, ...) RETURNS <datatype>
<do>
RETURN <variable_name>
ENDFUNCTION

Array

Define Array:
One-dimension Array

  • 1D array
1
DECLARE <variable_name> : ARRAY[<lower>:<upper>] OF <datatype>

Two-dimension Array

  • 2D array
1
DECLARE <variable_name> : ARRAY[<low>:<up>, <low>:<up>] OF <datatype>

Assignment

  • Assign a value to a specified position
1
<array_name>[i] ← <data>

User defined datatype

Non-composite

Enumerated

Composite

Record
Definition:

  1. hold a set of data
  2. different data types
  3. under one identifier
  • Compact datatype
1
2
3
4
5
6
TYPE <type_name>
DECLARE <subtype_name1> : <data_type>
DECLARE <subtype_name2> : <data_type>
DECLARE <subtype_name3> : <data_type>
......
ENDTYPE

data_type: INTEGER, CHAR, BOOLEAN, REAL, STRING, DATE

  • Assignment
1
2
DECLARE <variable_name> : <type_name>
<variable_nale>.<subtype_name1> ← <data>

Learn Computer Science
https://jrp1401.com/2025/06/01/learn-computer-science/
Author
Jerry
Posted on
June 1, 2025
Licensed under