Friday, May 20, 2022 20:54

Table of contents >> Introduction > Conditional processing

Conditional processing

Now that we are done with data types, we can finally start learning about doing something useful with that data. Conditional processing is one of the most basic forms of allowing your programs to perform an useful action.

As you noticed, all the programs presented so far in our lessons started the execution with the Main method, and continued subsequently with the following instructions. As your programs will become more and more complex, you will encounter situations where you will want to perform a certain action if a condition is true, and another action if it is false. For instance, you might have a program that needs to display a different greeting for each day of the week. You would have to first check if the current day is equal to a certain day of the week, and if it is, display that day’s greeting; if not, check if the current day is equal to another certain day of the week, and so on. Whenever your program executes (or not) a certain action based on a certain condition, the program executes a conditional processing. In order to execute a conditional processing, your program evaluates a condition, returning a True or False result. As an example, “Today is Friday” can either be True or False. There is no “in between”. To help with conditional processing, C# offers you the if, if-else, if-else if-else, and switch instructions. In the following lessons, we will focus on these concepts of the conditional processing.

The concepts explained in this lesson are also shown visually as part of the following video:


Leave a Reply

Follow the white rabbit