Online Pseudocode Interpreter
Online Pseudocode Interpreter Guide
Loreto G. Gabawa Jr.

BEGIN and END Command

Your Pseudocode should always start with BEGIN and END commands.

For Example:

begin
# the rest of your codes
end

Comments

Comments in pseudocode are essential for providing explanations, clarifications, and context to make your algorithm understandable to both yourself and others. Here's a guide on using comments effectively in pseudocode.

# to denote a single-line comment.

For Example:

begin
# I am a comment, the interpreter will ignore me
end

DISPLAY Command

The DISPLAY command will display any values in the OUTPUT area of the application

For Example:

begin
display "Hello World"
end

Variable Declaration

In pseudocode, you don't need to explicitly declare variables like you do in some programming languages. You can simply start using a variable by assigning a value to it.

Variable names should be chosen to reflect the meaning or purpose of the data they store. It's a good practice to use descriptive names that convey the intention of the variable.

For example:

begin
 total = 0 # Assigning a value to 'total'
end

Arithmetic Operators

Arithmetic operators perform basic mathematical operations.

  • Addition (+): Adds two values.
  • Subtraction (-): Subtracts the right-hand value from the left-hand value.
  • Multiplication (*): Multiplies two values.
  • Division (/): Divides the left-hand value by the right-hand value.
  • Modulus (%): Returns the remainder of division.
# Addition
result = 5 + 3 # result is 8
# Subtraction
result = 10 - 4 # result is 6
# Multiplication
result = 6 * 2 # result is 12
# Division
result = 8 / 2 # result is 4

Arithmetic Expressions

Arithmetic expressions involve basic mathematical operations like addition, subtraction, multiplication, and division.

begin
x = 1
y = 2
result = (3 * x) + (y / 2)
display result
end

String Concatenation

Concatenation joins strings together. You can use the + operator or the built-in strConcat function.

begin
firstName = "John"
lastName = "Doe"
fullName = firstName + " " + lastName
display fullName
end

Using the built-in function:

begin
greeting = strConcat("Hello, ", "world!")
display greeting
end

Comparison Operators

Comparison operators are used to compare two values and return a Boolean result (true or false).

  • Equal to (==): Checks if two values are equal.
  • Not equal to (!=): Checks if two values are not equal.
  • Greater than (>): Checks if the left-hand value is greater than the right-hand value.
  • Less than (<): Checks if the left-hand value is less than the right-hand value.
  • Greater than or equal to (>=): Checks if the left-hand value is greater than or equal to the right-hand value.
  • Less than or equal to (<=): Checks if the left-hand value is less than or equal to the right-hand value.
# Equal to
5 == 5 # is equal is true
# Not equal to
7 != 3 # not equal is true
# Greater than
10 > 5 # is_greater is true
# Less than
3 < 8 # is_less is true
# Greater than or equal to
5 >= 5 # is_greater_or_equal is true
# Less than or equal to
4 <= 3 # is_less_or_equal is false

Logical Operators

Logical operators combine Boolean values (true or false) to form more complex conditions.

  • AND (&&): Returns true if both operands are true.
  • OR (||): Returns true if at least one operand is true.
1 == 1 && 0 == 0 # both are true
1 == 0 || 0 == 0 # either are true

IF Statement

The basic structure of an "IF" statement consists of the "IF" keyword, a condition to be evaluated, and the code to execute if the condition is true.

begin
num = 0
if num == 0
display "Number is zero."
endif
end

Nested IF Statements

You can nest "IF" statements inside each other to create more complex conditions.

begin
num = 0
if num > 0
if num == 1
display "Number is one"
endif
endif
end

Multiple Conditions

You can use parentheses to group conditions and define the order of evaluation.

begin
num = 0
if num > 0 && num == 1
if num == 1
display "Number is one"
endif
endif
end

While Statement

The while statement in pseudocode is a looping construct that allows you to repeatedly execute a block of code as long as a specified condition is true. It's a fundamental control structure used for tasks that require iteration or repetition. Here's how it works:

begin 
number = 1
while number < 5
display number
number = number + 1
endwhile
end

Built-in Functions

The interpreter provides several built-ins you can call like normal functions:

  • print(x): print a value (no newline).
  • println(x) or display x: print with newline.
  • wait(ms): pause execution for the given milliseconds.
  • arraySize(arr): return number of elements in an array.
  • strLen(str): get the length of a string.
  • strConcat(str1, str2): concatenate two strings.
  • split(string, regex): split a string by regex into an array.

Note: Interactive input is not supported in the browser UI.

begin
 msg = strConcat("Hello, ", "world!")
 display msg
 display strLen(msg)
 arr = split("a,b,c", ",")
 display arraySize(arr)
end