Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- -- Create a program that will keep asking the user for his input until he enters two numbers
- -- That means if he enters anything that is not a number, ask the user to enter a number again
- -- Once you obtain two numbers, create a pattern like this
- -- n1 = 3, n2 = 2
- -- **
- -- **
- -- **
- -- height == 3, width == 2
- n1 = nil;
- n2 = nil;
- while (type(n1) ~= "number") do -- if type of n1 is not a number, keep asking the user to enter a number
- print("Enter number 1:");
- n1 = tonumber(io.read()); -- read the value from the console and use tonumber(n1) to transform it into a number, if successful, n1 is type number, otherwise n1 is type nil
- end
- while (type(n2) ~= "number") do
- print("Enter number 2:");
- n2 = tonumber(io.read());
- end
- for i = 1, n1 do -- this loop create lines
- for j = 1, n2 do -- this loop creates columns inside of lines
- io.write("*"); -- io.write outputs to console without a space (new line), creates stars in a line
- end
- print(); -- create a new line
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement