Advertisement
Lucas_3D

loops in loops

Nov 5th, 2021 (edited)
66
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.01 KB | None | 0 0
  1. numbers = #(1,2,3,4,5,6,7,8,9,10)
  2. colours = #("Red","Orange","Yellow","Green","Blue","Indigo","Violet","Cyan","Magenta","Brown")
  3. things =#("Hand","Car","Bottle","Torch","Wheel","Leaf","Bike","Shoe","Bird","Robot")
  4. --
  5. for num in numbers do print num
  6. --
  7. for col in colours do print col
  8. --
  9. for num in numbers do
  10. (
  11. for col in colours do
  12. (
  13. print (num as string + " " + col)
  14. )
  15. )
  16. --
  17. for col in colours do
  18. (
  19. for num in numbers do
  20. (
  21. print (col + " " + num as string)
  22. )
  23. )
  24. --this next one may help in seeing how 3 loops are working
  25. for num1 in numbers do
  26. (
  27. for num2 in numbers do
  28. (
  29. for num3 in numbers do
  30. (
  31. print (num1 as string + " " + num2 as string + " " + num3 as string)
  32. --like how you were envisaging a flexible function, you can see how you can add syntax between the variables to run something useful.
  33. )
  34. )
  35. )
  36. --okay 3 loops
  37. for num in numbers do
  38. (
  39. for col in colours do
  40. (
  41. for thing in things do
  42. (
  43. print (num as string + " " + col + " " + thing)
  44. )
  45. )
  46. )
  47.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement