Conditional is an instruction or operation that is executed or performed only if certain criteria are met. In the context of programming languages, a conditional statement is written in code to create a pathway or a set of rules for a computer or machine to follow in order to make decisions, execute processes or procedures, or take a specific action when an event or action occurs. Conditional operations are useful for dynamically altering the path of program execution depending on certain conditions or values. For example, a conditional operation could be used in a program to display a message if the user enters a certain value.
• If … then … — This type of statement is used to test a condition and execute a statement or block of code if the condition is true.
• Switch…case… — A switch statement is used to evaluate a variable or expression against a list of different possible values and execute a statement or block of code based on the first matching value.
• For … do… — The for statement is used to execute a statement or block of code a certain number of times, which can be determined at run time.
• While … do … — The while statement is used to execute a statement or block of code while a certain condition remains true.
• Try…catch… — The try…catch statement is used to handle errors in programs.
Conditional operations are usually written in a set of statements and can contain other conditional operations or loops within them. Conditionals are used in virtually every programming language, and are a fundamental part of programming.