Rolcam

Computercraft Tutorial - Section 7 - Loops

Jun 14th, 2021 (edited)
987
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Lua 1.04 KB | None | 0 0
  1. --This is part of a Computercraft Programming Teaching Program
  2.  
  3. tSides = {"left","right","bottom","top","front","back"}
  4.  
  5. for i = 1, #tSides do
  6.   monitor = peripheral.wrap(tSides[i])
  7.   if monitor then
  8.         side = tSides[i]
  9.         break
  10.   end
  11. end
  12. --Prevents program termination
  13. os.pullEvent = os.pullEventRaw
  14. term.redirect(peripheral.wrap(side))
  15.  
  16. -- Resets Screen
  17. function reset()
  18. term.setTextColor(colors.white)
  19. term.setBackgroundColor(colors.black)
  20. term.clear()
  21. term.setCursorPos(1,1)
  22. end
  23.  
  24. reset()
  25. print("Section 7 - Loops \n ")
  26. print("These are also useful in more complex programs. They can provide logic to a program.")
  27. print("Remember to always put \"end\" as the last line to close the loop\n ")
  28. print("while a == 1 do - While the variable \"a\" is equal to 1, keep looping /n")
  29. print("for <start>, <end>, <interval> do - this is a more advanced loop.")
  30. print("for a = 1, 10 do - Interval is optional. It sets a local variable to the loop \"a\" as 1 and")
  31. print("stops looping when \"a\" is equal to 10 \n ")
  32. term.restore()
Add Comment
Please, Sign In to add comment