r/CodingForBeginners • • Oct 31 '26

Pseucodecode check?

Did some pseudocode for something due tomorrow concerning arrays. would like to know if my logic concerning arrays is skewered. It's formatted the way it is due to the teacher's preference lol/

Problem

Search the web to discover 10 commonly used passwords and store them in an array. Write pseudocode to represent the logic of a program that prompts a user for a password, then displays an error message and continues to prompt until the user has not chosen one of the common passwords.

CODE:

START

 

//HOUSEKEEPING

DECLARE USER_PASSWORD

DECLARE COMMON_PASSWORDS[10]

DECLARE INDEX

DECLARE MATCH_FOUND

 

SET COMMON_PASSWORDS[0] = "123456"

SET COMMON_PASSWORDS[1] = "password"

SET COMMON_PASSWORDS[2] = "qwerty"

SET COMMON_PASSWORDS[3] = "111111"

SET COMMON_PASSWORDS[4] = "12345678"

SET COMMON_PASSWORDS[5] = "123456789"

SET COMMON_PASSWORDS[6] = "admin"

SET COMMON_PASSWORDS[7] = "abc123"

SET COMMON_PASSWORDS[8] = "123123"

SET COMMON_PASSWORDS[9] = "iloveyou"

 

//INPUT

DISPLAY "Enter a password:"

INPUT USER_PASSWORD

 

//PROCESS

SET MATCH_FOUND = TRUE

 

WHILE MATCH_FOUND = TRUE

 

SET MATCH_FOUND = FALSE

 

FOR INDEX = 0 TO 9

 

IF USER_PASSWORD = COMMON_PASSWORDS[INDEX] THEN

SET MATCH_FOUND = TRUE

ENDIF

 

ENDFOR

 

IF MATCH_FOUND = TRUE THEN

DISPLAY "ERROR: Password is too common. Please enter a different password:"

INPUT USER_PASSWORD

ENDIF

 

ENDWHILE

 

//OUTPUT

 DISPLAY "Password accepted."

END

3 Upvotes

9 comments sorted by

View all comments

1

u/binarycow Nov 04 '26

If it were me, I'd use a "do" loop instead of a "while" loop, for this case. It gets rid of the weirdness with how you initialize the loop condition variable, and highlights that the loop is always executed once.

Instead of:

match_found = true // But you haven't found it yet! 
while match_found
    match_found = false
    do stuff
end while

You do this:

match_found = false // since we haven't found it
do
    do stuff
while match_found

Of course, this is assuming that your language has the concept of a do loop. If it doesn't, your while loop is written correctly.

Edit: I just realized, it's not written correctly. Your condition is inverted. You want to loop while the match is not found. I did not update my code example accordingly, I'm showing a one-to-one comparison to what you originally wrote.