Rolcam

Computercraft Tutorial - Section 6 - If/Else Statements

Jun 14th, 2021 (edited)
804
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  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 6 - If/Else Statements \n ")
  26. print("These are useful in more complex programs. They provide basic logic to a program. \n ")
  27. print("if a == 1 then - If the variable \"a\" equals 1, then the program will print \"Hello\"")
  28. print("print(\"Hello\")")
  29. print("elseif a == 2 then - Otherwise, if \"a\" is equal to 2 then the program will print ")
  30. print("print(\"Goodbye\")")
  31. print("\"else\" - Otherwise the program will print \"Hello World\"")
  32. print("print(\"Hello World\")")
  33. print("end - Designates the end of the if statement \n ")
  34. term.restore()
RAW Paste Data