Learn Gambas - 10 Code Examples & CST Typing Practice Test
Gambas is a free, object-oriented programming language and development environment based on BASIC, designed primarily for Linux. It allows rapid development of graphical, database, and console applications, with a visual IDE similar to Visual Basic.
Learn GAMBAS with Real Code Examples
Updated Nov 21, 2025
Code Sample Descriptions
Gambas Counter and Theme Toggle
DIM count AS INTEGER = 0
DIM isDark AS BOOLEAN = FALSE
PROCEDURE updateUI()
PRINT "Counter: "; count
IF isDark THEN
PRINT "Theme: Dark"
ELSE
PRINT "Theme: Light"
END IF
END PROCEDURE
PROCEDURE increment()
count += 1
updateUI()
END PROCEDURE
PROCEDURE decrement()
count -= 1
updateUI()
END PROCEDURE
PROCEDURE reset()
count = 0
updateUI()
END PROCEDURE
PROCEDURE toggleTheme()
isDark = NOT isDark
updateUI()
END PROCEDURE
' Simulate actions
updateUI()
increment()
increment()
toggleTheme()
decrement()
reset()
Demonstrates a simple counter with theme toggling using Gambas variables and procedures.
Gambas Random Number Generator
FOR i = 1 TO 3
PRINT "Random "; i; ": "; Rnd(1,100)
NEXT
Generates random numbers between 1 and 100 and prints them.
Gambas Todo List
DIM todos AS NEW Collection
PROCEDURE addTask(task AS String)
todos.Add(task)
FOR EACH t AS String IN todos
PRINT t;
NEXT
END PROCEDURE
PROCEDURE removeTask(index AS Integer)
todos.RemoveAt(index)
FOR EACH t AS String IN todos
PRINT t;
NEXT
END PROCEDURE
' Simulate actions
addTask("Buy milk")
addTask("Write Gambas code")
removeTask(0)
Maintains a simple todo list with add and remove functionality.
Gambas Dice Roller
FOR i = 1 TO 3
PRINT "Roll "; i; ": "; Rnd(1,6)
NEXT
Rolls a six-sided dice three times.
Gambas Countdown Timer
DIM count AS INTEGER = 5
WHILE count >= 0
PRINT "Countdown: "; count
count -= 1
WEND
PRINT "Done!"
Counts down from 5 to 0.
Gambas Prime Checker
FUNCTION isPrime(n AS Integer) AS Boolean
IF n < 2 THEN RETURN FALSE
FOR i = 2 TO Sqr(n)
IF n MOD i = 0 THEN RETURN FALSE
NEXT
RETURN TRUE
END FUNCTION
DIM nums AS INTEGER[] = [7,10,13]
FOR EACH n AS Integer IN nums
PRINT n; " is "; IIF(isPrime(n), "Prime", "Not Prime")
NEXT
Checks if numbers are prime.
Gambas Temperature Converter
FUNCTION cToF(c AS Double) AS Double
RETURN c * 9 / 5 + 32
END FUNCTION
FUNCTION fToC(f AS Double) AS Double
RETURN (f - 32) * 5 / 9
END FUNCTION
PRINT "25°C = "; cToF(25); "°F"
PRINT "77°F = "; fToC(77); "°C"
Converts Celsius to Fahrenheit and Fahrenheit to Celsius.
Gambas Shopping Cart
DIM cart AS NEW Collection
DIM prices AS NEW Collection
PROCEDURE addItem(item AS String, price AS Integer)
cart.Add(item)
prices.Add(price)
PRINT "Cart: "; cart
PRINT "Total: "; prices.Sum
END PROCEDURE
PROCEDURE removeItem(index AS Integer)
cart.RemoveAt(index)
prices.RemoveAt(index)
PRINT "Cart: "; cart
PRINT "Total: "; prices.Sum
END PROCEDURE
' Simulate actions
addItem("Apple", 2)
addItem("Banana", 3)
removeItem(0)
Adds and removes items in a shopping cart with total cost.
Gambas Name Greeting
PROCEDURE greet(name AS String)
PRINT "Hello, "; name; "! Welcome!"
END PROCEDURE
' Simulate actions
greet("Saurav")
greet("Alice")
greet("Bob")
Greets users by name.
Gambas Stopwatch
DIM time AS INTEGER = 0
WHILE time < 5
PRINT "Stopwatch: "; time; " seconds"
time += 1
WEND
PRINT "Done!"
Simulates a stopwatch incrementing seconds.
Frequently Asked Questions about Gambas
What is Gambas?
Gambas is a free, object-oriented programming language and development environment based on BASIC, designed primarily for Linux. It allows rapid development of graphical, database, and console applications, with a visual IDE similar to Visual Basic.
What are the primary use cases for Gambas?
Developing Linux GUI applications. Rapid prototyping for desktop software. Database applications with MySQL, PostgreSQL, or SQLite. Educational purposes for learning programming. Small utility and productivity tools on Linux
What are the strengths of Gambas?
Rapid development for Linux desktop applications. Intuitive syntax similar to Visual Basic. Built-in IDE with GUI designer. Supports modern object-oriented programming. Active open-source community with extensions
What are the limitations of Gambas?
Primarily Linux-focused, limited Windows/Mac support. Smaller ecosystem compared to mainstream languages. Less suitable for performance-critical applications. Limited industrial adoption. Relatively smaller community and documentation
How can I practice Gambas typing speed?
CodeSpeedTest offers 10+ real Gambas code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.