我需要ruby的帮助

  1. 我正在制作一个软件,但我现在不想发布它的源代码,因为我不想让人们偷走我的辛勤工作。 我不粗鲁或类似的东西。 下面是我正在制作的程序的示例。
print "Username : " name = gets.chomp print "Password : " pass = gets.chomp if name =="user" and pass=="pa$$word" print "Hello" else print "Error, incorrect details" 

现在这是ruby中最简单的登录表单,但是这里发生的不好的事情是当用户插入错误的信息时程序将关闭,我想要发生的是我想让程序要求用户提供正确的信息,直到正确的信息是插入。

  1. 你是Windows用户吗? 知道如何在批处理文件中编程吗? 例子

    echo Hello world cls

暂停

所以这是ruby的代码

 a. print "Command : " b. command = gets.chomp c. if command == "Hello" d. print "Hi, how are you?" e. elsif command == "help" f. print "Say hi to me, chat with me" 

现在我想要的就像第一个问题一样

详细信息:用户输入“Hi”后,程序就会关闭,但是我想在这里让程序要求再次排队

使用while循环不断请求输入并检查用户的提交,直到输入有效结果。

 username = nil while username.nil? puts "What is your username?" entered_username = gets.chomp if entered_username == "Bob" username = entered_username end end puts "Thanks!" 

在终端上运行时,会产生:

 What is your username? sdf What is your username? dsfsd What is your username? sdfsd What is your username? sdfds What is your username? sdf What is your username? Bob Thanks! 

1。

 until (print "Username : "; gets.chomp == "user") and (print "Password : "; gets.chomp == "pa$$word") puts "Error, incorrect details" end puts "Hello" 

2。

 loop do print "Command : " case gets.chomp when "Hello" then print "Hi, how are you?"; break when "help" then print "Say hi to me, chat with me"; break end end 

这是简单的方法:)如果有人遇到问题我遇到的所有你做的就是这个。 “while”循环

 number = 1 # Value we will give for a string named "number" while number < 10 # The program will create a loop until the value # of the string named "number" will be greater than 10 puts "hello" # So what we need to do now is to end the loop otherwise # it will continue on forever # So how do we do it? # We will make the ruby run a script that will increase # the string named "number"'s value every time we run the loop number = number + 1 end # Now what happens is every time we run the code all the program # will do is print "hello" and add number 1 to the string "number". # It will continue to print out "hello" until the string is # greater than 10