Structure -- Control Structures
Control structures: a fundamental part of coding. Control structures help determine which path to go, like in a fork in the road. Let's first start off with a basic structure:
{
//code stuff (remember that // means comma)
}
Here's the control structure: {} Whatever goes in here is going to be executed, depending on the type of control structure. Let's look at some of these.
if (x==1)
{//do this}
else
{//do that}
Here's the control structure here: if statements. If statements compare two values. In this case, x and 1. What goes in the parenthesis () is a boolean expression. If the boolean expression reads true, the program will execute the {//do this} part. I'll explain the else later, but first, here are the boolean/comparison operators you can put into those parenthesis...
== equal to
!= not equal to
< less than
> greater than
<= less than or equal to
>= greater than or equal to
Well, these are basic ones. You should know these...hopefully. I'll now show examples of each of these operators with if statements...
if (1==1)
{//execute}
if (1 != 0)
{//execute}
if (0<1)
{//execute}
if (1>0)
{//execute}
if (1<=4)
{//execute}
if (4 >= 1)
{//execute}
All these examples had the boolean expressions returning a value of true, therefore allowing the code to proceed to executing whatever is in the {}.
{
//code stuff (remember that // means comma)
}
Here's the control structure: {} Whatever goes in here is going to be executed, depending on the type of control structure. Let's look at some of these.
if (x==1)
{//do this}
else
{//do that}
Here's the control structure here: if statements. If statements compare two values. In this case, x and 1. What goes in the parenthesis () is a boolean expression. If the boolean expression reads true, the program will execute the {//do this} part. I'll explain the else later, but first, here are the boolean/comparison operators you can put into those parenthesis...
== equal to
!= not equal to
< less than
> greater than
<= less than or equal to
>= greater than or equal to
Well, these are basic ones. You should know these...hopefully. I'll now show examples of each of these operators with if statements...
if (1==1)
{//execute}
if (1 != 0)
{//execute}
if (0<1)
{//execute}
if (1>0)
{//execute}
if (1<=4)
{//execute}
if (4 >= 1)
{//execute}
All these examples had the boolean expressions returning a value of true, therefore allowing the code to proceed to executing whatever is in the {}.