Advertisement
Guest User

video_4_example_1

a guest
Oct 21st, 2016
122
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 0.99 KB | None | 0 0
  1. -- Create a program that will keep asking the user for his input until he enters two numbers
  2. -- That means if he enters anything that is not a number, ask the user to enter a number again
  3.  
  4. -- Once you obtain two numbers, create a pattern like this
  5. -- n1 = 3, n2 = 2
  6. -- **
  7. -- **
  8. -- **
  9.  
  10. -- height == 3, width == 2
  11.  
  12.  
  13. n1 = nil;
  14. n2 = nil;
  15.  
  16. while (type(n1) ~= "number") do -- if type of n1 is not a number, keep asking the user to enter a number
  17.     print("Enter number 1:");
  18.     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
  19. end
  20.  
  21. while (type(n2) ~= "number") do
  22.     print("Enter number 2:");
  23.     n2 = tonumber(io.read());
  24. end
  25.  
  26.  
  27. for i = 1, n1 do -- this loop create lines
  28.     for j = 1, n2 do -- this loop creates columns inside of lines
  29.         io.write("*"); -- io.write outputs to console without a space (new line), creates stars in a line
  30.     end
  31.     print(); -- create a new line
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement