Skip to content

Commit

Permalink
groovy: decorate the console
Browse files Browse the repository at this point in the history
  • Loading branch information
tungbq committed Sep 9, 2023
1 parent 2e35c9b commit 1fa2346
Showing 1 changed file with 18 additions and 1 deletion.
19 changes: 18 additions & 1 deletion topics/groovy/helloworld/basic-concept.groovy
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
// Function to print log messages in green color
def consoleLog(message) {
println "\u001B[32m[INFO] $message\u001B[0m"
}

// Greetings!
println "Welcome to Groovy!"
consoleLog("Welcome to Groovy!")

//------------------------
// Working with variables
Expand All @@ -13,6 +18,8 @@ println "${myName} is ${myAge} years old!"
// Working with if-else
//-------------------

consoleLog("Working with if-else")

def number = 10

if (number > 5) {
Expand All @@ -25,6 +32,8 @@ if (number > 5) {
// Working with switch-case
//-----------------------

consoleLog("Working with switch-case")

def myFruit = "Banana"

switch (myFruit) {
Expand All @@ -45,6 +54,8 @@ switch (myFruit) {
// Working with for loop
//--------------------

consoleLog("Working with for loop")

def fruits = ["Apple", "Banana", "Cherry", "Watermelon", "Elderberry"]

for (fruit in fruits) {
Expand All @@ -55,6 +66,8 @@ for (fruit in fruits) {
// Working with functions
//----------------------

consoleLog("Working with functions")

def factorial(n) {
if (n == 0) {
return 1
Expand All @@ -73,6 +86,8 @@ println("Factorial of 5 is: $result")
// Working with Map in Groovy
//-----------------------

consoleLog("Working with Map in Groovy")

// Create a map with key-value pairs
def person = [
"firstName": "John",
Expand Down Expand Up @@ -100,6 +115,8 @@ person.each { key, value ->
// Working with try-catch
//--------------------

consoleLog("Working with try-catch")

def divideNumbers(int dividend, int divisor) {
try {
def result = dividend / divisor
Expand Down

0 comments on commit 1fa2346

Please sign in to comment.