1. Home
  2. /
  3. Eiffel
  4. /
  5. Prime Checker

Prime Checker - Eiffel Typing CST Test

Loading…

Prime Checker — Eiffel Code

Checks if a number is prime.

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

Eiffel Language Guide

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.

Primary Use Cases

  • ▸High-reliability enterprise software
  • ▸Safety-critical systems
  • ▸Reusable component libraries
  • ▸Formal software engineering projects
  • ▸Educational use for software engineering principles

Notable Features

  • ▸Design by Contract
  • ▸Strong static typing
  • ▸Generic classes and collections
  • ▸Multiple inheritance with controlled resolution
  • ▸Automatic memory management (garbage collection)

Origin & Creator

Eiffel was created by Bertrand Meyer in the late 1980s at ETH Zurich and later developed further at Interactive Software Engineering.

Industrial Note

Eiffel is used in safety-critical systems, mission-critical enterprise applications, embedded systems requiring high reliability, and software frameworks emphasizing correctness.

More Eiffel Typing Exercises

Eiffel Counter and Theme ToggleEiffel Fibonacci SequenceEiffel Factorial CalculatorEiffel Sum of ArrayEiffel Reverse StringEiffel Multiplication TableEiffel Temperature ConverterEiffel Simple Alarm SimulationEiffel Random Walk Simulation

Practice Other Languages

CReactPythonC++RustTypeScriptKotlinPHPJavaC#RubyMqlCqlN1qlCypher