Wednesday, November 25, 2015

"If" statements

In C++ the most basic for of camands are If statements. Unlike loops, which obviously loop, if statements sipmly complete a command once a condition or multiple conditions are met. It's the most simple way to get soething done, and without it C++ would be very difficult to do anything. If statements (Using the example from yesterday) look like this:
if(int MP==4)
{
bool parity=true;
}
Here it is broken down. The if(int MP==4) is first stating that this is an if statement, and everything inside the parentheses are conditions that must be met for the if statement to take effect. int is creating an integer and MP is giving the integer its name. The ==4 is setting the condition. In this case, that condition is when MP equals 4. YOU CANNOT WRITE MP=4, AS THAT WOULD MEAN SOMETHING COMPLETLEY DIFFERENT! Everything inside the curly brakcets is what will happen once the if statement activates. So, this if statement is saying "If the integer MP equals 4, than the bool parity is true."
So that's if statements, but their exsistance is dangerous. Unexperienced programmers often abuse the if staments. Instead of writing a while or for loop which is simpler and more effiecent they will code many MANY if statements instead. This is commonly refered to as "hard coding" and it's not a good thing to do. It takes up much more time and despite looks, it also gives you less control over your code. That's not to say you shouldn't use them. If statements are important and ther are many things that can only be done with if statements. So if statements aren't bad. You just need to use them properly.

No! I was just a little boy of a Nisovin *cough cough cough* I think...
-GIR