C#. 2.2 statements

Source: Internet
Author: User

Second, the statement: order, Branch, loop.

(i) Order: slightly

Branch: Judgment--expression.

if () {} Four categories:

1.if

if (age > 18)

{Console.WriteLine ("Can go to the army!")         "); }

Note: You can omit {} after the if expression, but you must add {} If you want to pipe multiple sentences after the IF expression.

2.if...else ...

if (age > 18)

{Console.WriteLine ("Grown Up! ");

Console.WriteLine ("Can go to the army!") ");

Else

{Console.WriteLine ("Not yet grown! ");

Console.WriteLine ("Go home to school!")             "); }

Note: Do not add semicolons after 1.else. Do not add parentheses after 2.else.

3.if...else

If...else if...else multiple branches.

Input

Console.Write ("What time is the wolf old Wolf?" ");

string s = Console.ReadLine ();

int hour = Convert.ToInt32 (s);

if (hour >= 0 && Hour < 6)//0

{Console.WriteLine ("Wee" + Hour + "dot"); }

else if (hour >= 6 && hour <= 12)

{Console.WriteLine ("Morning" + hour + "point up"); } 、

else if (Hour > && Hour < 18)

{hour-= 12;             Console.WriteLine ("PM" + hour + "point up"); }

else if (hour >= && Hour < 24)

{hour-= 12;             Console.WriteLine ("Night" + Hour + "point up"); }

Else

{Console.WriteLine ("Unrecognized time!             "); }

4.if nesting. Nested in above 3 use

Stratification, classification to solve the problem of ideas.

C #. 2.2 statement

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.