Do...while in "A piece of code" switch

Source: Internet
Author: User

1#include <stdio.h>2 intMain ()3 {4  intn=5;5  Switch(n) {6      Case 0: Do{7      Case 1:p rintf ("1");8      Case 2:p rintf ("2");9      Case 3:p rintf ("3");Ten      Case 4:p rintf ("4"); One      Case 5:p rintf ("5"); A     default: n--; -} while(n>2); - } theprintf"\ n"); - return 0; -}

The switch statement mechanism is the same as the Goto statement (similar?). ), you can implement an unconditional jump. -This is the more reliable answer I can ask.

1 Goto Label; 2  Do {3    Label: 4     printf ("123"); 5   }  while (0);
There is no difference between jumping to the middle of a loop with a goto and jumping into the loop with a switch, and the case determines the starting position. called the label statement. Here switch (n) jumps directly to the execution of the sentence case 5 there, output 5, and then still in the Do...while loop, at this time the case in Do...while, the default has been invalidated, that is, directly after the execution of their statements, step-up execution, until n=2, Loop end. Running result: 51234512345.

Do...while in "A piece of code" switch

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.