Genie で簡単なパスワード チェック ルーチンを作成したいのですが、for ループでスタックしてしまいました。模倣したいpythonコードは次のとおりです。
#-----------------------------------------------
# password_test.py
# example of if/else, lists, assignments,raw_input,
# comments and evaluations
#-----------------------------------------------
# Assign the users and passwords
users = ['Fred','John','Steve','Ann','Mary']
passwords = ['access','dog','12345','kids','qwerty']
#-----------------------------------------------
# Get username and password
usrname = raw_input('Enter your username => ')
pwd = raw_input('Enter your password => ')
#-----------------------------------------------
# Check to see if user is in the list
if usrname in users:
position = users.index(usrname) #Get the position in the list of the users
if pwd == passwords[position]: #Find the password at position
print 'Hi there, %s. Access granted.' % usrname
else:
print 'Password incorrect. Access denied.'
else:
print "Sorry...I don't recognize you. Access denied."
これが私が得ることができる限りです:
[indent=4]
init
users: array of string = {"Fred","John","Steve","Ann","Mary"}
passwords: array of string = {"access","dog","12345","kids","qwerty"}
print "Enter user name"
var usrname = stdin.read_line()
print "Enter password"
var pwd = stdin.read_line()
var position = 1
var i = 1
for i=0 to i < users.length
if (users[i]==usrname)
position += 1
if pwd == passwords[position]
print "Hi there, %d. Access granted."
else
print "Password incorrect. Access denied."
else
print "Sorry...I don't recognize you. Access denied."
ただし、コンパイラでエラーが発生しています。
$ valac evenmores.gs
evenmores.gs:15.18-15.18: error: syntax error, expected `do' but got `<' with previous identifier
for i=0 to i < users.length
^
Compilation failed: 1 error(s), 0 warning(s)
ここで提案されているように、forループも試しました:
for (i = 0; i < users.length; i++)
役に立たない。助けていただければ幸いです。ありがとう。