MatthewC
MatthewC

Reputation: 63

Expressing "equals" in pseudocode

I was just wondering if there is a special way of saying when something equals something. For example in python, if you declare something equals 2, you say something = 2, whereas when you check if something equals something else, you would say: if something == somethingelse:

So my question is in pseudocode for algorithms if I'm checking to see if a entered password equals a stored password in an IF THEN ELSE ENDIF loop, would I use one or two equal signs:

WHILE attempts < 3
    Get EnteredPassword
    **IF EnteredPassword = StoredPassword THEN**
        Validated = TRUE
    ELSE
        attempts = attempts + 1
    ENDIF
ENDWHILE

Upvotes: 1

Views: 5573

Answers (2)

Serpent101
Serpent101

Reputation: 1

To express equals you use the equal mark symbol once, unlike in python where you use the symbol twice to compare two values (eg if variable == 'one'). An example syntax is:

variable = 'one'

WHILE variable = 'one' DO

SEND "hi" TO DISPLAY

Upvotes: 0

metahexane
metahexane

Reputation: 119

Usually, pseudocode is very broad and every author has their own way of expressing it. As Aziz has noted, usually x <- 1 is used for an assignment and x := x + 1 for an update. Read ':=' as 'becomes' instead of 'equals', however, they are interchangeably used. As for your question, both = and == are accepted answers, as long as it is clear to your reader what your intention is.

Upvotes: 2

Related Questions