You are on page 1of 15

Deluge

• Getting Started
 Welcome!
 Variables
 Data Types
 Operators
 Expressions
 Comments
Conditional Statements
 List
 Map
Getting Started
• Welcome
Syntax
info <expression>;
info is used as a debugger statement which would print out the given expression on the output
console.

Example
info "Hi, there!!";

Print your name with the help of info statement.

• info “Subhash”;info statement.


Variables
Syntax
<variable_name> = <expression>;

Great ! Now let's get started with the Variables.


Variables are defined to store a value.

Check out the following example which would create a variable name with value as "John".

Example
name = "John";
info name;

TRY IT OUT
Create a variable product_name and set it's value as "Milk" and Try to print the value of the variable.
product_name = "Milk";
info product_name;
Data Types
Now we'll learn about different types of variables which we can create in deluge script. The static values are nothing but known as
constants.

Follow the given example which would create a variable of type number(Bigint), float (Decimal) and boolean (Bool) in order (Other data
types will be covered later).

Example
age = 22; // Bigint
pi = 3.14; // Decimal
isWeekend = false; // Bool

TRY IT OUT
Create another variable product_quantity with value as 5 , product_price with value as 20.50 & isAvailable with value as true.
Try to print their values too in the same order.
product_name = "Milk";
product_quantity = 5;
product_price = 20.5;
isAvailable = true;
Operators
Operators are used to compute arithmetic operations between two operands (i.e variable or any constant).

Following example shows the conversion of Temperature from Celsius to Fahrenheit.

Example
C = 39;
F = C * 9/5 + 32;
info F;

TRY IT OUT
Create a variable price with value 85 and quantity with value 6. Now try to find out the Total
price.
price = 85;
quantity = 6;
Total_Price= price * quantity;
info Total_Price;

OUTPUT
510
Expressions
Combinations of variables, constants and operators are expressions. Following example shows how to concatenate firstName
and lastName as fullName and to find the length of it.

Example
first_name = "John";
last_name = "Smith";
full_name = first_name + last_name;
//Put a dot to apply function on a variable
info full_name.length();

TRY IT OUT
Create a variable product_name with value as Milk Powder. Now print the value of product_name in lowercase.
product_name = "Milk Powder";
info product_name.lower();
OUTPUT
milk powder
Comments
Syntax
// <write your comments here> Single Line
/*
Multiline comments are used for large text descriptions or to comment out chunks
of code.
*/
Comments generally help to understand the code better and the commented out code will never be
executed.
Example
// name = "John";
name = "John Smith";
/*
It's a holiday !!
Have Fun !!
*/
isWeekend = true;
// product_price =500
product_price=500;
info product_price;
CONDITIONAL STATEMENTS
if
Syntax
if ( <condition> )
{
// Executes if condition is true
<statements>
}
Conditional Statements execute the mentioned condition and if it evaluates to true then the statments mentioned in the block
will be executed, otherwise execution proceeds to the next block of statement if exists.
Example
marks = 70;
if (marks >= 40)
{
info "Pass !!";
}
TRY IT OUT
Check if product_quantity is greater than equal to 1 then print "Available".
product_quantity = 5;
if (product_quantity >=5)
{
info "Avaialable";
}
CONDITIONAL STATEMENTS
else
Syntax
if ( <condition> )
{
// Executes if condition is true
<statements>
}
else
{
// Executes if condition is false
<statements>
}
Else is a branch of if statement. If the given condition is false, the statements specified under else block will be executed.

Example TRY IT OUT


marks = 30;
if (marks >= 40)
Check if product_quantity is greater than 0 then
{ print "Available" otherwise print "Not Available".
info "Pass !!"; product_quantity = 0;
} if ( product_quantity >= 0)
else OUTPUT
{ { Avaialble
info "Fail !!"; info "Avaialble";
} }
else
{
info "Not Avaiable";
}
It is one of the branch of if statement. which
CONDITIONAL STATEMENTS cannot be cannot be executed separately.
else if always expects root i.e if statement can
else if have multiple else if and will be executed on
failure of previous if / else if statement and
Syntax condition mentioned in else if statement.
if ( <condition1> )
Example
{ marks = 70;
// Executes if condition1 is true if (marks >= 40)
{
<statements> info "Pass !!";
} }
else if (marks < 40)
else if ( <condition2> ) {
info "Fail !!";
{
}
// Executes if condition2 is true
<statements>
}
LIST
New List
Syntax
<variable> = List();
<variable> = {}; //put comma separated values
List is a collection variable which holds a collection of data based on index. Insertion and retrive values
are based on index. Index starts from 0.
Insertion order will be maintained and values will not be sorted by default. Duplicate values are allowed
TRY IT OUT
to be inserted. Create a list variable products with the values as "Milk" and
Example "Bread" and print the list
languages = {"English", "French", "German"};
products = {"Milk", "Bread"};
info languages;
info products;

OUTPUT
Milk,Bread

You might also like