Basic Syntax
Dive deeper into the language syntax and structure.
In this tutorial you will create and run your first complete program in Quetzal Language, exploring the basic features of the language.
Let’s start with the classic “Hello, World” program:
Create the file
Create a new file named hola_mundo.qz in your preferred folder.
Write the code
// My first program in Quetzal Languageconsola.mostrar("Hola, mundo desde Quetzal!")Run the program
Open Command Prompt or PowerShell in the folder where you saved the file and run:
quetzal hola_mundo.qzExpected result
Hola, mundo desde Quetzal!Congratulations! You just ran your first program in Quetzal.
Now let’s create a more complete program that demonstrates various features of the language:
Create a file named mi_primer_programa.qz:
/* My first complete program in Quetzal Language Author: Your name Date: Today*/
consola.mostrar_exito("=== MY FIRST QUETZAL PROGRAM ===")
// ===== VARIABLES AND TYPES =====consola.mostrar_informacion("1. Working with variables...")
// Basic typesentero edad = 25texto nombre = "Ana Garcia"numero salario = 2500.50log esta_empleado = verdadero
// Display variablesconsola.mostrar("Name: " + nombre)consola.mostrar("Age: " + edad.texto() + " years")consola.mostrar("Salary: $" + salario.texto())consola.mostrar("Employed: " + esta_empleado.texto())
// ===== LISTS =====consola.mostrar_informacion("2. Working with lists...")
lista<texto> hobbies = ["programar", "leer", "viajar", "cocinar"]lista<entero> numeros_favoritos = [7, 13, 21, 42]
consola.mostrar("Hobbies: " + hobbies.texto())consola.mostrar("Favorite numbers: " + numeros_favoritos.texto())
// ===== FUNCTIONS =====consola.mostrar_informacion("3. Using functions...")
// Function to calculate circle areanumero calcular_area_circulo(numero radio) { numero pi = 3.14159 retornar pi * radio * radio}
// Function to create personalized greetingtexto crear_saludo(texto nombre_persona, entero edad_persona) { si (edad_persona >= 18) { retornar "Hello " + nombre_persona + ", you are an adult" } sino { retornar "Hello " + nombre_persona + ", you are a minor" }}
// Use the functionsnumero area = calcular_area_circulo(5.0)texto saludo = crear_saludo(nombre, edad)
consola.mostrar("Circle area (radius 5): " + area.texto())consola.mostrar(saludo)
// ===== CONDITIONALS =====consola.mostrar_informacion("4. Using conditionals...")
entero puntuacion = 85
si (puntuacion >= 90) { consola.mostrar("Grade: Excellent")} sino si (puntuacion >= 80) { consola.mostrar("Grade: Very Good")} sino si (puntuacion >= 70) { consola.mostrar("Grade: Good")} sino { consola.mostrar("Grade: Needs Improvement")}
// ===== LOOPS =====consola.mostrar_informacion("5. Using loops...")
consola.mostrar("Counting from 1 to 5:")para (entero i = 1; i <= 5; i++) { consola.mostrar("Number: " + i.texto())}
consola.mostrar("Iterating through hobbies:")para (texto hobby en hobbies) { consola.mostrar("- " + hobby)}
// ===== JSON OBJECTS =====consola.mostrar_informacion("6. Working with JSON...")
jsn persona = { nombre: nombre, edad: edad, salario: salario, hobbies: hobbies, contacto: { email: "ana@example.com", telefono: "+502 1234-5678" }, activo: verdadero}
consola.mostrar("Person data:")consola.mostrar(persona.texto_formateado())
// ===== MATHEMATICAL OPERATIONS =====consola.mostrar_informacion("7. Mathematical operations...")
entero a = 15entero b = 4
consola.mostrar("Operations with " + a.texto() + " and " + b.texto() + ":")consola.mostrar("Sum: " + (a + b).texto())consola.mostrar("Subtraction: " + (a - b).texto())consola.mostrar("Multiplication: " + (a * b).texto())consola.mostrar("Division: " + (a / b).texto())consola.mostrar("Modulo: " + (a % b).texto())
// ===== MUTABLE VARIABLES =====consola.mostrar_informacion("8. Mutable variables...")
entero var contador = 0consola.mostrar("Initial counter: " + contador.texto())
contador = contador + 10consola.mostrar("Counter after adding 10: " + contador.texto())
contador += 5consola.mostrar("Counter after += 5: " + contador.texto())
// ===== END =====consola.mostrar_exito("Program completed successfully!")consola.mostrar("You have learned the basic concepts of Quetzal Language")quetzal mi_primer_programa.qzIn Quetzal, variables are declared with their type first:
entero edad = 25 // Integertexto nombre = "Ana" // Stringnumero precio = 99.99 // Decimal numberlog activo = verdadero // BooleanBy default, variables are immutable. Use var for mutable variables:
entero var contador = 0contador = contador + 1 // This worksFunctions are defined with their return type, name, and parameters:
numero calcular_area(numero radio) { retornar 3.14159 * radio * radio}
// Function without return valuevacio mostrar_mensaje(texto mensaje) { consola.mostrar(mensaje)}Conditionals use si, sino si, and sino:
si (edad >= 18) { consola.mostrar("Adult")} sino si (edad >= 13) { consola.mostrar("Teenager")} sino { consola.mostrar("Child")}Quetzal supports multiple loop types:
// Traditional for looppara (entero i = 0; i < 5; i++) { consola.mostrar(i.texto())}
// For-each looppara (texto item en lista) { consola.mostrar(item)}
// While loopmientras (condicion) { // code}Basic Syntax
Dive deeper into the language syntax and structure.
Data Types
Explore all available data types and their methods.
Functions
Learn about functions, parameters, and return values.
More Examples
Explore more practical examples and projects.