Learn Eiffel - 10 Code Examples & CST Typing Practice Test
Eiffel is a high-level, object-oriented programming language designed for software engineering with a strong emphasis on correctness, reusability, and maintainability. It supports the Design by Contract methodology, promoting robust and reliable applications.
Learn EIFFEL with Real Code Examples
Updated Nov 20, 2025
Code Sample Descriptions
Eiffel Counter and Theme Toggle
class
COUNTER
feature
count: INTEGER
is_dark: BOOLEAN
update_ui
do
io.put_string ("Counter: " + count.out + '\n')
io.put_string ("Theme: " + (if is_dark then "Dark" else "Light") + '\n')
end
increment
do
count := count + 1
update_ui
end
decrement
do
count := count - 1
update_ui
end
reset
do
count := 0
update_ui
end
toggle_theme
do
is_dark := not is_dark
update_ui
end
end
! Simulate actions
local
c: COUNTER
do
create c
c.update_ui
c.increment
c.increment
c.toggle_theme
c.decrement
c.reset
end
Demonstrates a simple counter with theme toggling using Eiffel classes and methods.
Eiffel Fibonacci Sequence
class
FIBONACCI
feature
compute
do
local a, b, c, i: INTEGER
a := 0
b := 1
io.put_integer(a); io.put_new_line
io.put_integer(b); io.put_new_line
from i := 1 until i > 8 loop
c := a + b
io.put_integer(c); io.put_new_line
a := b
b := c
i := i + 1
end
end
end
! Run
local
f: FIBONACCI
do
create f
f.compute
end
Generates first 10 Fibonacci numbers.
Eiffel Factorial Calculator
class
FACTORIAL
feature
compute (n: INTEGER)
local f, i: INTEGER
do
f := 1
from i := 1 until i > n loop
f := f * i
i := i + 1
end
io.put_string ("Factorial: "); io.put_integer(f); io.put_new_line
end
end
! Run
local
fact: FACTORIAL
do
create fact
fact.compute(5)
end
Calculates factorial of a given number.
Eiffel Prime Checker
class
PRIME_CHECKER
feature
is_prime (n: INTEGER): BOOLEAN
local i: INTEGER
do
from i := 2 until i >= n loop
if n \ i = 0 then
Result := False
return
end
i := i + 1
end
Result := True
end
end
! Run
local
p: PRIME_CHECKER
num: INTEGER
do
num := 13
create p
if p.is_prime(num) then
io.put_string ("Prime"); io.put_new_line
else
io.put_string ("Not Prime"); io.put_new_line
end
end
Checks if a number is prime.
Eiffel Sum of Array
class
ARRAY_SUM
feature
sum_array (arr: ARRAY[INTEGER])
local total, i: INTEGER
do
total := 0
from i := arr.lower until i > arr.upper loop
total := total + arr[i]
i := i + 1
end
io.put_string ("Sum: "); io.put_integer(total); io.put_new_line
end
end
! Run
local
a: ARRAY_SUM
arr: ARRAY[INTEGER]
i: INTEGER
do
create a
create arr.make(1,5)
arr[1] := 1; arr[2] := 2; arr[3] := 3; arr[4] := 4; arr[5] := 5
a.sum_array(arr)
end
Calculates the sum of an array of integers.
Eiffel Reverse String
class
REVERSE_STRING
feature
reverse (s: STRING)
local i: INTEGER; result: STRING
do
create result.make_empty
from i := s.count until i = 0 loop
result.append_character(s[i])
i := i - 1
end
io.put_string(result); io.put_new_line
end
end
! Run
local
r: REVERSE_STRING
s: STRING
do
create r
s := "Hello"
r.reverse(s)
end
Reverses a string.
Eiffel Multiplication Table
class
MULT_TABLE
feature
print_table (n: INTEGER)
local i: INTEGER
do
from i := 1 until i > 10 loop
io.put_integer(n); io.put_string (" x "); io.put_integer(i); io.put_string (" = "); io.put_integer(n * i); io.put_new_line
i := i + 1
end
end
end
! Run
local
t: MULT_TABLE
do
create t
t.print_table(5)
end
Prints the multiplication table of a number.
Eiffel Temperature Converter
class
TEMP_CONVERTER
feature
c_to_f (c: REAL)
local f: REAL
do
f := (c * 9.0 / 5.0) + 32.0
io.put_real(f); io.put_new_line
end
end
! Run
local
t: TEMP_CONVERTER
do
create t
t.c_to_f(25.0)
end
Converts Celsius to Fahrenheit.
Eiffel Simple Alarm Simulation
class
ALARM_SIMULATION
feature
check_temperature (temp, threshold: INTEGER)
do
if temp > threshold then
io.put_string("Alarm: Temperature Too High!"); io.put_new_line
else
io.put_string("Temperature Normal"); io.put_new_line
end
end
end
! Run
local
a: ALARM_SIMULATION
do
create a
a.check_temperature(80, 75)
end
Simulates a simple alarm when a threshold is reached.
Eiffel Random Walk Simulation
class
RANDOM_WALK
feature
simulate (steps: INTEGER)
local i, position: INTEGER
do
position := 0
from i := 1 until i > steps loop
if random(2) = 0 then
position := position + 1
else
position := position - 1
end
io.put_integer(position); io.put_new_line
i := i + 1
end
end
end
! Run
local
rw: RANDOM_WALK
do
create rw
rw.simulate(10)
end
Simulates a random walk using integers.
Frequently Asked Questions about Eiffel
What is Eiffel?
Eiffel is a high-level, object-oriented programming language designed for software engineering with a strong emphasis on correctness, reusability, and maintainability. It supports the Design by Contract methodology, promoting robust and reliable applications.
What are the primary use cases for Eiffel?
High-reliability enterprise software. Safety-critical systems. Reusable component libraries. Formal software engineering projects. Educational use for software engineering principles
What are the strengths of Eiffel?
Encourages correct and maintainable code. Supports formal software engineering methodologies. Highly reusable libraries via genericity. Robust exception handling and error detection. Object-oriented features fully integrated with contract-based programming
What are the limitations of Eiffel?
Smaller developer community compared to mainstream languages. Limited third-party libraries and ecosystem. Less industry adoption for modern web/mobile applications. Verbose syntax for simple tasks. Learning curve for Design by Contract concepts
How can I practice Eiffel typing speed?
CodeSpeedTest offers 10+ real Eiffel code examples for typing practice. You can measure your WPM, track accuracy, and improve your coding speed with guided exercises.