How to resolve the algorithm Enumerations step by step in the EGL programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Enumerations step by step in the EGL programming language

Table of Contents

Problem Statement

Create an enumeration of constants with and without explicit values.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Enumerations step by step in the EGL programming language

Source code in the egl programming language

// Without explicit values
enumeration FruitsKind
	APPLE,
	BANANA,
	CHERRY
end

program EnumerationTest
	
	function main()
		whatFruitAmI(FruitsKind.CHERRY);
	end
 
	function whatFruitAmI(fruit FruitsKind)
		case (fruit)
			when(FruitsKind.APPLE)
				syslib.writestdout("You're an apple.");
			when(FruitsKind.BANANA)
				syslib.writestdout("You're a banana.");
			when(FruitsKind.CHERRY)
				syslib.writestdout("You're a cherry.");
			otherwise
				syslib.writestdout("I'm not sure what you are.");
		end
	end

end

// With explicit values
library FruitsKind type BasicLibrary {}
	const APPLE int = 0;
	const BANANA int = 1;
	const CHERRY int = 2;
end

program EnumerationTest
	
	function main()
		whatFruitAmI(FruitsKind.CHERRY);
	end
 
	function whatFruitAmI(fruit int in)
		case (fruit)
			when(FruitsKind.APPLE)
				syslib.writestdout("You're an apple.");
			when(FruitsKind.BANANA)
				syslib.writestdout("You're a banana.");
			when(FruitsKind.CHERRY)
				syslib.writestdout("You're a cherry.");
			otherwise
				syslib.writestdout("I'm not sure what you are.");
		end
	end
	
end

  

You may also check:How to resolve the algorithm Mutex step by step in the Oforth programming language
You may also check:How to resolve the algorithm Zig-zag matrix step by step in the Objeck programming language
You may also check:How to resolve the algorithm Align columns step by step in the CoffeeScript programming language
You may also check:How to resolve the algorithm Hello world/Text step by step in the Nix programming language
You may also check:How to resolve the algorithm Inverted syntax step by step in the M2000 Interpreter programming language