Menu
Coddy logo textTech

The Main Loop

Part of the Logic & Flow section of Coddy's Lua journey — lesson 42 of 54.

challenge icon

Challenge

Easy

Expand your contact list application by implementing the main program loop that keeps the application running until the user decides to quit.

Building on the previous setup, create a while loop that continuously displays the menu and prompts the user for input. The loop should continue running until the user enters quit, at which point the program should exit gracefully.

Requirements:

  • Keep all code from the previous challenge (the contacts table and initial menu display)
  • After displaying the menu, print a blank line
  • Create a while true loop for the main application loop
  • Inside the loop, print the prompt: Enter command:
  • Read the user's input using io.read()
  • If the input is quit, print Goodbye! and break the loop
  • For any other input, print Command not yet implemented
  • After processing the command, print a blank line before the next prompt

Example interaction:

Welcome to Contact List Manager!

Available Commands:
add - Add a new contact
list - Display all contacts
search - Search for a contact
delete - Delete a contact
quit - Exit the program

Enter command:
add
Command not yet implemented

Enter command:
list
Command not yet implemented

Enter command:
quit
Goodbye!

Try it yourself

contacts = {}

print("Welcome to Contact List Manager!")
print()
print("Available Commands:")
print("add - Add a new contact")
print("list - Display all contacts")
print("search - Search for a contact")
print("delete - Delete a contact")
print("quit - Exit the program")

All lessons in Logic & Flow