If-Then Statements Rules And Uses
If you want to improve your writing, then you should study grammar. That is an example of a classic if-then statement. These statements are logic-based and conclude something that happens if certain conditions are met. However, the primary use for if-then statements is in science and math as they help prove certain conditions or hypotheses.
Uses Of The If-Then Statement
An if-then statement, which is also known as a conditional sentence, is usually found in math or scientific studies. Computer programming also uses these statements to check conditions. Depending on the outcome of the answer, they trigger blocks of information that tell the program what to do.
Scientists perform experiments to prove hypotheses by using a conditional sentence like if condition ‘a’ is present, then ‘b’ should be the result. For instance, if I insert the car key into the ignition and turn it, then the car should start. If it does start, then I can go to work. However, if the car doesn’t start, then I need to troubleshoot the problem to find out what is wrong with the car.
In this example, these conditional sentences depend on something happening. In this case, by turning the key in the ignition, the car should start. When the outcome doesn’t happen, then the condition needs to be reset by following another set of instructions, which in this case is to troubleshoot the car if it doesn’t start.
If/Then In Computer Programming
You probably encounter conditional sentences every day without being aware of it. If you’ve ever taken an online quiz, then you’ve had exposure to them. When selecting an answer to a quiz, the program is written using conditional sentences to react to the responses you’ve chosen.
For example, if the question is true or false, such as ‘the sky is green,’ and you select an answer, either true or false, then the response should be either correct or wrong. So, the programmer probably wrote something like if a = true, then b = wrong. If a = false, then b = correct.
Of course, conditional statements in coding can be much more complex, and it may be necessary to use an if-then-else statement. The idea is when the quiz taker answers a question, and it's correct, the program will issue a response like "correct," otherwise the response would be "wrong." So, an if/then/else statement in C++ would look like this:
For our example, when someone takes the quiz, and the question is ‘the sky is green,' and they press ‘a' for true, the correct response from the computer should be ‘wrong.’ So, the syntax might look like this:
Cout << ‘wrong’;
Cout << ‘correct’;
If you don’t do programming or don’t do it in C++, then this syntax will look odd. However, it instructs the computer what output it should have given for answers. Since it was a true or false quiz ‘a' was true, and ‘b' would be false. So, if ‘a' was the answer, this if/then/else statement assumes ‘b’ is the correct response and it is written in such a way.
Depending on the number of questions, the program can be very long. For instance, if a true/false quiz has 10 questions, then there are 20 possible answers the program will give. Each question will have two possible responses, either “correct” or “wrong.”
Conditional Sentences In Excel
If you’re evaluating the information for an experiment, then you could use Excel to test the variables. For example, if you were tracking the participants in a study to determine their ages, you could use if-then statements to track the information.
Many scientific studies will track participants by demographic information like their names, ages, gender, weight, races, etc. If the demographic information is on a spreadsheet, each column could hold a specific piece of information.
It may have the name in the first column, birth year in the second, birth month in the third, birthday in the fourth, gender in the fifth, and so on until all the information was on the sheet. Then, the next empty column could contain a conditional sentence to sort the data, so the researchers can quickly find their answers.
An example would be to find study participants who are senior citizens. So, they would set the age for a senior citizen at 55 and find out who was born before 1964. The answer to this conditional sentence for each person would be in this column, ‘yes’ they were born before 1964 or ‘no’ they were not.
In Excel, you can do an if-then statement as a formula. The title for the new column could be ‘Born Before 1964.’ Then, in the first empty cell, begin typing the formula in it. So, you would type ‘=IF,' and at this point, a prompt box will open and give you options on how to continue the formula.
In this case, the first entry is ‘If’ and beneath it says, ‘returns value depending on logical expression.’ If you have a more up-to-date version of Excel, it may say ‘logical_test.” Either way, select the first applicable prompt.
Then insert the number of the cell that has the birth year, which may be the one after the name or the third one after the name depending on how the information is on the spreadsheet. Let's pretend the second column on the spreadsheet is for the birth year so that it could be column ‘B.'
In the formula, inside the open parentheses, type ‘B2.’ Since we are looking for birth years less than 1964, type the less than symbol, which is a caret pointing to the left ‘<’ type the year with a comma ‘1964,’ then “yes," "no” and close the parentheses.
So, the formula looks like this: =If(B2<1964,” yes” ,”no”).
In Excel speak it says, if cell B2 is less than 1964, then the answer is "yes." If it is greater than 1964, then the answer is "no." To get the result for all of the cells in the ‘B' column, you can right-click on the edge of the first cell, and it should display a '+,' which you can drag to the end of the column where the information stops. That copies and pastes the formula to each cell.
Since the answer to the question needs to appear on the spreadsheet, use quote marks around the answer that will appear. In this case, it is "yes" or "no." The if-then formula can go into any column where you need to sort specific information. You can sort the demographics based on age, weight, height, race, education, or anything else you need to know for a study.
If/Then For Scientific Studies
When testing theories, conditional sentences are often applied to reach conclusions. The scientist may write out his or her hypothesis as ‘If a takes place…’ In the example above, the hypothesis was ‘If the key is in the ignition and turned,…’ The latter part of the sentence, or the ‘then’ statement is the conclusion. In the example, the conclusion would be that the car would start, ‘then the car starts.’
The scientist would then go on to write experiments to see if the hypothesis and the conclusion were correct. If the car didn't start, the scientist could take their research further to find out why not or what was wrong with the car to prevent it from starting. if-then statements are also very prevalent in math, especially geometry or trigonometry, but they can appear in algebraic formulas too.
Conditional Sentences As Proofs
The usage of conditional sentences in math is usually proofs. So, the hypotheses may be that if most of the world's population is right-handed, then the remaining population is left-handed. To write it out in an equation, "most of the world's population is right-handed," would be assigned the letter R for right-handed and "the remaining population is left-handed," would be L for left-handed.
The equation would be R→ L.
An inversion of the formula would be L → R.
This states if the remaining population of the world is left-handed, then most of the world’s population is right-handed. Mathematical equations proving conditional sentences are the same as in science, with the equation being its shorthand. So, if you have a hypothesis, such as ‘ if it is snowing, then clouds are in the sky,’ you could express it as:
S → C; If it is snowing, then clouds are in the sky.
An algebraic if-then statement could be ‘if x=3, then x2 = 9.' Conditional sentences in math and science can be much more complicated so that we won't go into them here, these are just simple examples of how if-then statements in the two fields of study are used.
However, they are more common in computer programming to display answers to a quiz or to meet other conditions that are necessary to present information on a screen. These can be very complex as well. Expressing conditional sentences in written language is easy. In fact, several of them are in this article, can you spot them?