Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
⌘/⌃ F
Show / Hide find an replace menu
⌘/⌃ O
Load a local file into the editor
⌘/⌃ S
Save current editor content to a local file
Introduction to Conditional Structures
In pseudocode, there are two types of conditional structures that are utilised, being IF statements and CASE statements.
IF statements utilise a specific set of keywords that need to be included, being IF, THEN, ENDIF.
IF <condition> THEN
<code to be executed>
ENDIFE.g:
IF num1 = 3 THEN
OUTPUT "num1 is 3"
ENDIFIF statements can also include an ELSE clause to be able to branch into other code depending on if the IF statement has passed or not.
IF <condition> THEN
<code to be executed>
ELSE
<code to otherwise be executed>
ENDIFE.g:
IF num1 = 3 THEN
OUTPUT "num1 is 3"
ELSE
OUTPUT "num1 isn't 3"
ENDIFNested IF statements can also be used, however, care must be taken with inserting ENDIFs into the correct locations. An example of this would be:
IF num1 = 3 THEN
IF num2 = 3 THEN
OUTPUT "num1 and num2 are 3"
ELSE
OUTPUT "Only num1 is 3"
ENDIF
ELSE
IF num2 = 3 THEN
OUTPUT "Only num2 is 3"
ELSE
OUTPUT "Neither num1 or num2 is 3"
ENDIF
ENDIFCASE statements are where multiple branches of code can be executed, depending on the value of the variable given to the statement. They follow the keywords CASE OF, ENDCASE.
CASE OF <variable>
<value1> : <code to be executed>
<value2> : <code to be executed>
etc...
ENDCASEE.g:
CASE OF num1
1 : OUTPUT "num1 is 1"
2 : OUTPUT "num1 is 2"
3 : OUTPUT "num1 is 3"
ENDCASEAn OTHERWISE clause can be added, which acts similarly to an ELSE clause. It must always be the last case.
CASE OF <variable>
<value1> : <code to be executed>
<value2> : <code to be executed>
etc...
OTHERWISE : <code to be executed>
ENDCASEE.g:
CASE OF num1
1 : OUTPUT "num1 is 1"
2 : OUTPUT "num1 is 2"
3 : OUTPUT "num1 is 3"
OTHERWISE : OUTPUT "num1 is not 1, 2 or 3"
ENDCASEIntroduction to Functions and Procedures
Functions are algorithms that can be called to execute an already written set of code, and return a value to where they were called. They use the keywords FUNCTION, RETURNS, ENDFUNCTION. Functions can be used either with or without parameters.
FUNCTION <function name> RETURNS <data type to return>
<code to be executed>
ENDFUNCTIONAlternatively, with parameters:
FUNCTION <function name>(<parameter1> : <data type>,
<parameter2> : <data type>...)
RETURNS <data type to return>
<code to be executed>
ENDFUNCTIONThe keyword RETURN is used to specify a value to be returned within the function. Upon encountering a RETURN statement, it is executed immediately, and any lines after the statement are ignored.
FUNCTION Add(num1 : INTEGER, num2 : INTEGER) RETURNS INTEGER
num3 <- num1 + num2
RETURN num3
ENDFUNCTIONProcedures are similar to functions, however they do not return any value. They use the keywords PROCEDURE, ENDPROCEDURE. Procedures can also be used with or without parameters.
PROCEDURE <procedure name>
<code to be executed>
ENDPROCEDUREWith parameters:
PROCEDURE <procedure name>(<parameter1> : <data type>,
<parameter2> : <data type>...)
<code to be executed>
ENDPROCEDUREProcedures must be called using the CALL keyword, used respectively as follows:
CALL <procedure name>CALL <procedure name>(<parameter1>, <parameter2>, ...)An example of procedure definition and calling:
PROCEDURE Add(num1 : INTEGER, num2 : INTEGER)
num3 <- num1 + num2
OUTPUT num3
ENDPROCEDURE
CALL Add(10, 5)Introduction to Inputting and Outputting Data
To input values, the INPUT command is used, however the variable that is being input into must first be declared, as follows:
DECLARE <variable name> : <data type>
INPUT <variable name>An example of this would be:
DECLARE num1 : INTEGER
INPUT num1To output values, the OUTPUT command is used, as follows:
OUTPUT <value>Multiple values can be output at the same time by using commas between each value.
OUTPUT <value1>, <value2>, <value3>An example of a single output would be:
OUTPUT num1Or multiple outputs:
OUTPUT num1, num2, num3How to help update Pseudonaja
Ready to contribute? Here’s how to set up Pseudonaja for local development.
First you must fork the repo relevant to what you plan to change. Then you must clone the repo to your local machine in order to make changes.
$ git clone git@github.com:PutYourUsernameHere/editor.git$ git clone git@github.com:PutYourUsernameHere/docs.git$ git checkout -b name-of-your-bugfix-or-featureNow make your changes.
While there are no automated tests set up, it is highly encouraged that you thoroughly test anything your changes may have effected.
If your changes effect the codemirror files, you will need to roll up the editor files to a single file for use in the browser. The repo is already set up with a rollup configuration, so simply run:
$ npx rollup -cThen just run the server:
$ node index.jsOnce you are sure your changes work and haven't broken anything, push them to your forked repo.
$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-featureDocumentation on what is pseudonaja
Follow our handy guides to get started on the basics as quickly as possible:
Declaring Variables and ArraysConditional StructuresLoop StructuresFunctions and ProceduresRecordsIntroduction to Records
A record is a composite data type that contains multiple different data types. It contains multiple data items that can be accessed via dot notation. They are defined with keywords TYPE, ENDTYPE, and contain declarations:
Then, variables can be declared of the data type that has been defined, to be able to access elements within. To access items within the data type, the name of the variable is used, followed by a dot, then the name of the item to be accessed.
Introduction to Loop Structures
There are 3 types of loop structures that are used within pseudocode, which are pre-condition, post-condition and count controlled loops.
This type of loop is likely the one that most are familiar with, where the loop is controlled by a condition set before the loop. It follows the structure of WHILE, ENDWHILE.
It may not execute at all, depending on the set condition. E.g:
The expression will continue evaluating until the condition becomes FALSE, at which point the loop terminates.
This type of loop depends on a condition set after the code within it has executed once, as the condition is evaluated after the code. It follows the structure of REPEAT, UNTIL.
E.g:
This type of loop depends on a counter set within its initial statement. It follows the structure of FOR, TO, NEXT.
The value of the variable used as a counter can be assigned within the FOR statement.
The default increment value for the count variable is 1, however this can be changed with the addition of an extra keyword, STEP. A negative increment can be used, and as soon as the variable reaches a value equal to or above the limit, the loop terminates.
Introduction to Declaring Variables and Arrays in Pseudonaja
To use variables in Pseudonaja we first need to declare the variable. This can be done using the following command:
An example of this is:
Available data types:
To assign a value to a variable, instead of an = sign, an <- is used instead, after the variable has been declared.
In pseudocode you declare arrays slightly differently:
An example of this is:
Unlike lists in python arrays can only consist of a single data type as well as a fixed length.
Two dimensional arrays are declared as follows:
An example of this is:
To access a 1D array:
To access a 2D array:
Where the first value within the assignment statement is the row to be accessed, and the second value is the column to be accessed.
TYPE <data type name>
DECLARE <item1> : <type>
DECLARE <item2> : <type>
...
ENDTYPETYPE Person
DECLARE FirstName : STRING
DECLARE LastName : STRING
DECLARE FavFood : STRING
DECLARE Age : INTEGER
ENDTYPE
DECLARE Friend1 : Person
Friend1.FirstName <- "Jack"
Friend1.LastName <- "Pollier"
Friend1.FavFood <- "Lasagna"
Friend1.Age <- 17WHILE <condition>
<code to be executed>
ENDWHILEWHILE num1 < 5
num1 <- num1 + 1
ENDWHILEREPEAT
<code to be executed>
UNTIL <condition>REPEAT
num1 <- num1 + 1
UNTIL num1 = 10FOR <integer variable> TO <desired limit>
<code to be executed>
NEXT <integer variable that was used>FOR x <- 1 TO 10
OUTPUT x
NEXT xFOR <variable> TO <limit> STEP <increment>
<code to be executed>
NEXT <variable>DECLARE <variable name> : <data type>DECLARE num1 : INTEGERDECLARE num1, num2, num3 : INTEGERINTEGER
A single integer number
REAL
A single float / real number
BOOLEAN
A binary TRUE or FALSE value
CHAR
A single character
STRING
A string of multiple characters
ARRAY
An array of fixed length of a particular data type
num1 <- 3DECLARE <array name> : ARRAY [<lower bound>:<upper bound>] OF <data type>DECLARE myArray : ARRAY[0:100] OF INTEGERDECLARE <array name> ARRAY [<1ower bound 1>:<upper bound 1>, <1ower bound 1>:<upper bound 2>] OF <data type>DECLARE my2DArray ARRAY [0:100, 0:1] OF CHARDECLARE myArray : ARRAY[0:100] OF INTEGER
myArray[19] <- 29DECLARE my2DArray ARRAY [0:100, 0:1] OF CHAR
my2DArray[12, 1] <- 'B'