Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Loading...
Introduction to Declaring Variables and Arrays in Pseudonaja
This guide is going to take you through the process of basic declaration of variables 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:
You can also use commas to DECLARE multiple variables
Available data types:
INTEGER
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
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.
Documentation on what is pseudonaja
Pseudonaja is a CIE compliant pseudocode editor for GCSE, iGCSE and A-Level students studying computer science. We aim to provide an easy interface to write, edit and run pseudocode, with syntax inline with the CIE specification for examinations. Pseudonaja is an open source project with the code available using the GitHub link below.
Follow our handy guides to get started on the basics as quickly as possible:
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 Inputting and Outputting Data
This section will take you through basic inputting and outputting of data in Pseudonaja.
To input values, the INPUT command is used, however the variable that is being input into must first be declared, as follows:
An example of this would be:
To output values, the OUTPUT command is used, as follows:
Multiple values can be output at the same time by using commas between each value.
An example of a single output would be:
Or multiple outputs:
Introduction 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.
Alternatively, with parameters:
The 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.
Procedures 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.
With parameters:
Procedures must be called using the CALL keyword, used respectively as follows:
An example of procedure definition and calling:
Introduction 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.
How 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.
Now 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:
Then just run the server:
Once you are sure your changes work and haven't broken anything, push them to your forked repo.
A small number of keyboard shortcuts can be used with pseudonaja:
On macOS the special key is ⌘ (command)
On windows the special key is ⌃ (control)
⌘/⌃ 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.
E.g:
IF 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.
E.g:
Nested IF statements can also be used, however, care must be taken with inserting ENDIFs into the correct locations. An example of this would be:
CASE 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.
E.g:
An OTHERWISE clause can be added, which acts similarly to an ELSE clause. It must always be the last case.
E.g: