Skip to main content

Decision making statements - T24

As a programmer, it is essential for you to make your program to work better in all the cases. So, based on the real-time data, you have to decide how the program should work. So, it is important to take decision.

Consider a simple case where you want to print the number provided by the user at runtime is even or odd. How to handle that in programs? Decision making statements comes in to play.
So, what is the syntax and how to use that?

IF condition THEN
                This block will execute when the if condition is satisfied or validated to true.
END

This is the syntax of the simple IF block.

Ok. If the condition is not satisfied, then what will happen. I need to do something when IF condition is failed. How to handle that? ELSE block should be introduced. Here is the syntax,

IF condition THEN
                This block will execute when the if condition is satisfied or validated to true.
END ELSE
                This block will execute when the if condition is validated to false.
END

Let’s code a simple program to find whether it is even or odd?

PROGRAM FIND.EVEN.OR.ODD
                CRT “Input a number”
                INPUT GET_NUMBER
                IF MOD(GET_NUMBER,2) EQ 0 THEN
                                CRT “The number is Even”
                END ELSE
                                CRT “The number is Odd”
                END
END

MOD () – function allows to find modulus of a number. i.e. it will find the remainder of a division.

This simple if statement catered the above scenario but if you have a tons of scenarios to be checked what should be done.

Are you planning to do, Nested IF..ELSE,

Of course you can do that,

IF condition THEN
                Statements
                You can use NESTED IF ELSE here too.
END ELSE
                IF condition THEN
                                Statements
                END ELSE
                                statements
                END
                Statements
END

But this is a bad idea. If you have 2 or 3 cases to be checked you can use this. When there are about ten cases, using IF ELSE will reduce the readability of the code and it may prone to errors. So, what is the alternative?

SWITCH statements
Let’s see how it becomes an alternative and readability

BEGIN CASE
                CASE condition
                                statements
                CASE condition 
                                Statements
                CASE 1
                                Statements
END CASE

How the case statement works?
If the condition in first case becomes true, the rest of the cases will not be executed. CASE 1 is the default case, it will be executed if all the CASE fails.
You have to place the case statements very carefully for the logic to work properly and as expected by you.

Let’s see an example for CASE statement for the clear understanding, below is the scenario.
Consider a 10 litre container that contains water, if the water is less than 2 litres, you should print warning message. If that is between 5 and 7, print “Sufficient amount of water is available”. If that goes above 9.5, print “Container almost full”.

Let’s code it,
PROGRAM Water_Indicator
                CRT “Enter the amount of water in container”
                INPUT Capacity
                BEGIN CASE
                                CASE Capacity LE 2
                                                CRT “Warning: Water content is low”
                                CASE Capacity GT 2 AND Capacity LT 7
                                                CRT “Sufficient amount of water is available”
                                CASE Capacity GT 9.5
                                                CRT “Container almost full”
                                CASE 1
                                                CRT “Error Unable to receive the water level”
                END CASE
END


Hope you understand the CASE statements. Each CASE will carefully depict the flow and so it improves readability. Still any queries, please feel free to let us know in the comments.

Comments

Post a Comment

Popular posts from this blog

How to get 5GB instantly in seedr?

Seedr is a torrent caching site which provides 2GB of caching for free. For those who are not aware of what the torrent is?  Torrent is a peer to peer communication protocol (P2P) for file sharing. It was introduced in the mid of 2001 for decentralizing the file sharing in this real world. How the files are shared via torrent? Files are uploaded to servers as we do traditionally but the interesting part comes here, these files can be downloaded only via torrent client like Bit torrent, µtorrent, Vuze or you can use any other clients available in the market. Just do a google search to find all the available clients for downloading files.  Why they are restricting the download to clients? Because, the concept here is each computer acts as a server, once you start the download, the client will start uploading the data. Someone on the internet will download the same file based on the data you upload, this process is called seeding, thus decentralizing the data and reducing t

Hello World - Getting Started with T24

Are you looking to develop great modules and local services for T24? This is the perfect place to start with. Let’s start from the basics. The core banking platform, T24 is developed with INFOBASIC code. This is the proprietary language of Temenos. T24 has the unique compiler to convert the BASIC code to object files with TAFc (Temenos Application Framework c) platform. An another flavour TAFj (Temenos Application Framework java), converts the BASIC to bytecode making it capable to run on any device with the Java runtime installed. The BASIC code remains same for both TAFc and TAFj Platform. Enough Intro! Let’s say hello to this world, How the syntax of this basic program looks like, PROGRAM program_name all the basic statements reside inside this block END Now, it is right time say hello, PROGRAM HELLO                 CRT “Hello World” END Yah, we did that. But, how to run this. You need T24 deployed in your organisation to compile and run