What Is A Conditional Statements

Updated: January 25, 2022
No Credit Card Required
ClaimYour
FreeTrialClass

Transcript

People make an enormous amount of decisions every day, what to wear to school, whether to walk or bike it to take an umbrella, or not. The deciding factor between what you do and what you don't, is usually dictated by a condition. If it's raining, you probably won't even want to leave the house. Computers also have to make choices in a similar way.

Computer programs often contain scenarios for the computer to choose from and a conditional statement allows the computer to decide which scenario to go with. A conditional statement dictates the way a computer will react to a certain condition. If this happens, then do this. At the beginning, the computer checks whether a condition is being met and acts accordingly.

A programmer would write the several scenarios for the computer to choose people face and react to conditional statements in their everyday life as well. Riding on a bike through the city, you look out for traffic lights. If the traffic light is red, then you need to stop the bike. If it isn't, you keep on writing. In this example, the conditional statement is the color of the traffic light. When playing a game, conditional statements are pretty common. Imagine opening a door, it won't open until you have the right key. Or you could try to take a different approach. But as long as the condition isn't met, you will fail.

A conditional statement will lead to a set of instructions being carried out until an actual value has been reached. This value can be an input or internally generated. Conditional statements need to be carefully written so you don't create an error that will make the program run over and over again in an infinite loop. How exhausting.

Loading...