What follows from here are some control structures that exist in C#, as they often identically exist in
other languages. I will assume you understand how they work and how you use them, but if you don't know,
here's a
book
I might recommend you start with before moving on.
if (condition)
// do something
else if (otherCondition)
// do something else
else
// do this if the above two don't trigger
switch (evaluation)
{
case (value1): // do if "evaluation == value1"
break;
case (value2): // do if "evaluation == value2"
break;
...
default: // do this if nothing else above triggers
break;
}
while (condition)
{
// do stuff
}
do
{
// do stuff
} while (condition);
for ( initialization; exit condition; incrementation )
{
// do stuff
}
foreach (dataType slacker in CollectionOfThings)
{
// do stuff
}
As previously mentioned,
foreach iterates over a container of some kind (e.g.
arrays, vectors, sets, etc.) while the value of
slacker takes on the value
of each of the container's elements.
continue functions like it does from other languages. As does
break.