3.11 Lessons The exception statement repeats with the For loop

Source: Internet
Author: User

Exception statement Try Catch finally

try//protection execution inside the code snippet, if there is an error in one sentence, jump directly to the catch, will not control the following content
{
Console.Write ("Please enter an integer");
int a = Int. Parse (Console.ReadLine ());
Console.WriteLine ("Hello");
}
Exception found in Catch//try, executed directly, if no error in try, do not execute
{
Console.WriteLine ("Wrong input! ");
}
finally//no matter if there is any mistake, all need to execute!
{
Console.WriteLine ("Thanks for using, goodbye!") ");
}
Console.ReadLine ();

For Repeating Loop:

Case:

             for(inti =1; I <=3; i++)            {                if(i = =1) {Console.Write ("Do you love me or not? "); }                if(i = =2) {Console.Write ("I ask you, do you love me or not? "); }                if(i = =3) {Console.Write ("Are you deaf? I ask you love do not love me!! "); }                stringA =Console.ReadLine (); if(A = ="Love") {Console.WriteLine ("Well, I love you, too. "); System.Threading.Thread.Sleep ( -);//Sleep 2 secondsConsole.WriteLine ("from then on the prince and the princess had a shameless life! ");  Break; }                Else                {                    if(i = =3) {Console.WriteLine ("Get outta here! "); }}} console.readline ();

Enter month and date, determine whether the format is correct, if not correct, please re-enter:

Console.Write ("Please enter the year:");  for (; ; ) {                inty =int.                Parse (Console.ReadLine ()); if(Y >=0&& y <=9999) {Console.Write ("Please enter the month:"); intm =int.                    Parse (Console.ReadLine ());  for (; ; ) {                        if(M >=1&& m <= A) {Console.Write ("Please enter the date:");  for (; ; ) {                                intD =int.                                Parse (Console.ReadLine ()); if(d >=1&& D <= to)                                {                                    if(M = =1|| m = =3|| m = =5|| m = =7|| m = =8|| m = =Ten|| m = = A) {Console.WriteLine ("input is correct! The date you entered is"+ y +"years"+ M +"Month"+ D +"Day.");  Break; }                                    Else if(M = =4|| m = =6|| m = =9|| m = = One)                                    {                                        if(d <= -) {Console.WriteLine ("input is correct! The date you entered is"+ y +"years"+ M +"Month"+ D +"Day.");  Break; }                                        Else{Console.WriteLine ("the date you entered is malformed, please re-enter:"); }                                    }                                    Else                                    {                                        if(Y% -==0|| Y%4==0&& y% -!=0)                                        {                                            if(d <= in) {Console.WriteLine ("input is correct! The date you entered is"+ y +"years"+ M +"Month"+ D +"Day.");  Break; }                                            Else{Console.WriteLine ("the date you entered is malformed, please re-enter:"); }                                        }                                        Else                                        {                                            if(d <= -) {Console.WriteLine ("input is correct! The date you entered is"+ y +"years"+ M +"Month"+ D +"Day.");  Break; }                                            Else{Console.WriteLine ("the date you entered is malformed, please re-enter:");                                                                    }                                        }                                    } }                                Else{Console.WriteLine ("the date you entered is malformed, please re-enter:"); }                            }                             Break; }                        Else{Console.WriteLine ("The month format you entered is incorrect, please re-enter:"); }                    }                     Break; }                Else{Console.WriteLine ("the year you entered was incorrectly formatted, please retype it:"); }} console.readline ();

3.11 Lessons The exception statement repeats with the For loop

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.