Hi,
I tried four examples here, compiled for a 16F628.
First test:Result: 75 WORDSCode:IF CODE_ONE = 13 and CODE_TWO = 13 and CODE_THREE = 16 and CODE_FOUR = 21 and CODE_FIVE = 32 THEN 'Correct code ENDIF
Second test:Result: 26 WORDSCode:If CODE_ONE = 13 THEN IF CODE_TWO = 13 then if CODE_THREE = 16 then if CODE_FOUR = 21 then if CODE_FIVE = 32 THEN 'correct code Endif endif endif endif endif
Third test:RESULT: 26 WORDS (same as test 2)Code:IF CODE_ONE <> 13 THEN EXIT_TO_ERROR IF CODE_TWO <> 13 THEN EXIT_TO_ERROR IF CODE_THREE <> 13 THEN EXIT_TO_ERROR IF CODE_FOUR <> 13 THEN EXIT_TO_ERROR IF CODE_FIVE <> 13 THEN EXIT_TO_ERROR 'correct code EXIT_TO_ERROR:
Forth test:
This one uses an array to hold the entered code and assumes that the correct password sequence is stored in EEPROM, starting at location 0RESULT: 41 WORDSCode:Correct = 1 For i = 0 to 4 Read i, Password if Code[i] <> Password THEN Correct = 0 ENDIF NEXT If Correct THEN 'correct code endif
So between these four method 2 or 3 produces the smallest code - by far. Personally I think Aerostars suggestion is the easiest to read but that might just be me...
/Henrik.




Bookmarks