|
|
ASP.NET Tutorial 4: Conditionals ( if/else constructs )
by Matt on 2009/12/01 at 12:42 pm
A statement and it’s block together are known as a construct.
This is an if statement: (C#) if Statement:
if(strMyHair=="brown") This is a block: (C#) Code Block:
{
string strBleach = "blonde";
strMyHair = strBleach;
}
An if statement MUST have a code block following it – either one by itself will not work. Together, the statement and a block form a construct: (C#) if Construct:
if(strMyHair=="brown")
{
string strBleach = "blonde";
strMyHair = strBleach;
}
Prerequisites: ASP.NET Tutorial 3: Commenting & Documenting Code
This article will introduce you to conditionals in C#. Conditionals are a program’s decision-makers. They are used to evaluate and compare data, and then take different sets of actions based on the evaluations. It’s really not very different from the way humans make decisions. For instance, let’s say you’ve decided that you want go swimming… but only if it’s not too cold outside (because I live in sunny California, I’d consider anything 75 or under is “too cold”). If you can phrase a concept like that in English ("if it’s over 75 degrees outside, I’ll go swimming"), you can program it just as easily. Hopefully by the end of this article you will be able to write some of the most basic conditionals in C#… if |
No Comments