Online Pseudocode Interpreter
Online Pseudocode Interpreter Sample Codes
Loreto G. Gabawa Jr.

Displaying a Message:

begin
 message = "Hello, world!"
 display message
end
Output:
Hello, World!

Calculating the Sum of Numbers

begin
total = 0
counter = 1
max = 10
while counter < max
total = total + counter
counter = counter + 1
endwhile
display "The sum is: " + total
end
Output:
The sum is: 45

Finding the Maximum of Two Numbers:

begin
firstNumber = 1
secondNumber = 2
max = 0
if firstNumber > secondNumber
max = firstNumber
endif
else
max = secondNumber
endelse
display "The maximum is: " + max
end
Output:
The maximum is: 2

Calculating the Area of a Rectangle:

begin
 length = 12
width = 5
 area = length * width
 display "The area of the rectangle is: " + area
end
Output:
The area of the rectangle is: 60

Calculating the Factorial of a Number:

begin
 n = 5
 factorial = 1
i = 1
 while i < n
 factorial = factorial * i
i = i + 1
 endwhile
 display "The factorial of " + n
display "is " + factorial
end
Output:
The factorial of 5
is 24

String Operations (Length and Concatenation):

begin
 first = "Online"
 second = " Interpreter"
 combined = strConcat(first, second)
 display combined
 display strLen(combined)
end
Output:
Online Interpreter
19

Splitting a String:

begin
 sentence = "one,two,three"
 parts = split(sentence, ",")
 display parts[0]
 display parts[1]
 display parts[2]
end
Output:
one
two
three

Array Size and Update:

begin
 arr = [10, 20, 30]
 display arraySize(arr)
 arr[1] = 99
 display arr[1]
end
Output:
3
99

Functions with Parameters:

begin
 func add(a, b)
   display a + b
 endfunc

 add(7, 8)
end
Output:
15

Logical Operators:

begin
 a = 1
 b = 0
 display (a == 1) and (b == 0)
 display (a == 0) or (b == 0)
 display not (a == 0)
end
Output:
1
1
1