arrow-left

Only this pageAll pages
gitbookPowered by GitBook
1 of 12

Pseudonaja

Loading...

Guides

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Loading...

Extras

Loading...

Conditional Structures

Introduction to Conditional Structures

In pseudocode, there are two types of conditional structures that are utilised, being IF statements and CASE statements.

hashtag
IF 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>
ENDIF

E.g:

IF num1 = 3 THEN
    OUTPUT "num1 is 3"
ENDIF

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:

hashtag
CASE Statements

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:

IF <condition> THEN
    <code to be executed>
ELSE
    <code to otherwise be executed>
ENDIF
IF num1 = 3 THEN
    OUTPUT "num1 is 3"
ELSE
    OUTPUT "num1 isn't 3"
ENDIF
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
ENDIF
CASE OF <variable>
    <value1> : <code to be executed>
    <value2> : <code to be executed>
    etc...
ENDCASE
CASE OF num1
    1 : OUTPUT "num1 is 1"
    2 : OUTPUT "num1 is 2"
    3 : OUTPUT "num1 is 3"
ENDCASE
CASE OF <variable>
    <value1> : <code to be executed>
    <value2> : <code to be executed>
    etc...
    OTHERWISE : <code to be executed>
ENDCASE
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"
ENDCASE

Inputs and Outputs

Introduction to Inputting and Outputting Data

circle-info

This section will take you through basic inputting and outputting of data in Pseudonaja.

hashtag
Inputs

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:

hashtag
Outputs

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:

DECLARE <variable name> : <data type>

INPUT <variable name>
DECLARE num1 : INTEGER

INPUT num1
OUTPUT <value>
OUTPUT <value1>, <value2>, <value3>
OUTPUT num1
OUTPUT num1, num2, num3

Welcome to Pseudonaja

Documentation on what is pseudonaja

hashtag
About Us

circle-info

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.

hashtag
Guides: Jump right in

Follow our handy guides to get started on the basics as quickly as possible:

Declaring Variables and Arrayschevron-right
Conditional Structureschevron-right
Loop Structureschevron-right
Functions and Procedureschevron-right
Recordschevron-right

Functions and Procedures

Introduction to Functions and Procedures

hashtag
Functions

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>
ENDFUNCTION

Alternatively, with parameters:

FUNCTION <function name>(<parameter1> : <data type>,
                         <parameter2> : <data type>...)
                         RETURNS <data type to return>
    <code to be executed>
ENDFUNCTION

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.

hashtag
Procedures

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:

FUNCTION Add(num1 : INTEGER, num2 : INTEGER) RETURNS INTEGER
    num3 <- num1 + num2
    RETURN num3
ENDFUNCTION
PROCEDURE <procedure name>
    <code to be executed>
ENDPROCEDURE
PROCEDURE <procedure name>(<parameter1> : <data type>, 
                           <parameter2> : <data type>...)
    <code to be executed>
ENDPROCEDURE
CALL <procedure name>
CALL <procedure name>(<parameter1>, <parameter2>, ...)
PROCEDURE Add(num1 : INTEGER, num2 : INTEGER)
    num3 <- num1 + num2
    OUTPUT num3
ENDPROCEDURE

CALL Add(10, 5)

Declaring Variables and Arrays

Introduction to Declaring Variables and Arrays in Pseudonaja

circle-info

This guide is going to take you through the process of basic declaration of variables in Pseudonaja.

hashtag
Basic Variables

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:

circle-info

You can also use commas to DECLARE multiple variables

Available data types:

Datatype Command
Type
circle-exclamation

To assign a value to a variable, instead of an = sign, an <- is used instead, after the variable has been declared.

hashtag
Arrays

In pseudocode you declare arrays slightly differently:

An example of this is:

circle-exclamation

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:

hashtag
Accessing Arrays

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.

Loop Structures

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.

hashtag
Pre-Condition (WHILE)

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.

WHILE <condition>
    <code to be executed>
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.

hashtag
Post-Condition (REPEAT)

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:

hashtag
Count-Controlled (FOR)

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.

WHILE num1 < 5
    num1 <- num1 + 1
ENDWHILE

ARRAY

An array of fixed length of a particular data type

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

REPEAT 
    <code to be executed>
UNTIL <condition>
DECLARE <variable name> : <data type>
DECLARE num1 : INTEGER
DECLARE num1, num2, num3 : INTEGER
num1 <- 3
DECLARE <array name> : ARRAY [<lower bound>:<upper bound>] OF <data type>
DECLARE myArray : ARRAY[0:100] OF INTEGER
DECLARE <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 CHAR
DECLARE myArray : ARRAY[0:100] OF INTEGER

myArray[19] <- 29
DECLARE my2DArray ARRAY [0:100, 0:1] OF CHAR

my2DArray[12, 1] <- 'B'
REPEAT
    num1 <- num1 + 1
UNTIL num1 = 10
FOR <integer variable> TO <desired limit>
    <code to be executed>
NEXT <integer variable that was used>
FOR x <- 1 TO 10
    OUTPUT x
NEXT x
FOR <variable> TO <limit> STEP <increment>
    <code to be executed>
NEXT <variable>

Helping Develop Pseudonaja

How to help update Pseudonaja

hashtag
Get Started

Ready to contribute? Here’s how to set up Pseudonaja for local development.

hashtag
Clone a Repo

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.

hashtag
Changes To The Editor

hashtag
Changes To The Docs

hashtag
Create a Branch:

Now make your changes.

hashtag
Testing

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:

hashtag
Commit and Push Changes:

Once you are sure your changes work and haven't broken anything, push them to your forked repo.

hashtag
Submit a Pull Request to the Relevant GitHub Repo

Editorarrow-up-right
Documentationarrow-up-right

Records

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:

TYPE <data type name>
    DECLARE <item1> : <type>
    DECLARE <item2> : <type>
    ...
ENDTYPE

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.

TYPE 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 <- 17
$ git clone git@github.com:PutYourUsernameHere/editor.git
$ git clone git@github.com:PutYourUsernameHere/docs.git
$ git checkout -b name-of-your-bugfix-or-feature
$ npx rollup -c
$ node index.js
$ git add .
$ git commit -m "Your detailed description of your changes."
$ git push origin name-of-your-bugfix-or-feature

Classes

PseudonajaGitHubchevron-right
A link to the GitHub Repo
Logo

Keyboard Shortcuts

circle-info

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)

Shortcut
Action

⌘/βŒƒ F

Show / Hide find an replace menu

⌘/βŒƒ O

Load a local file into the editor

⌘/βŒƒ S

Save current editor content to a local file

https://pseudonaja.repl.copseudonaja.repl.cochevron-right
A Link to the online editor