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