#168 – Use if Statement to Conditionally Execute a Block of Code

You can use the if statement in C# to check the value of a boolean expression and execute a block of code only if the expression is true.

            if (userAge >= 50)
            {
                Console.WriteLine("Hey, you should consider joining AARP!");
                DisplayDetailsOfAARPMembership();
            }

If the value of the userAge variable is greater than or equal to 50, the block of code will be executed.  If the age is less than 50, the block will not be executed and the program will continue with the first statement after the block of code.

Advertisements

About Sean
Software developer in the Twin Cities area, passionate about software development and sailing.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: