What will the following program print for nesting switch into while loop? - C Statement

C examples for Statement:while

Description

What will the following program print for nesting switch into while loop?

Demo Code

#include <stdio.h> 
int main(void) 
{ 
    int i = 0; //w  w  w  .  j a  v a  2s.c om
    while ( i < 3) { 
       switch(i++) { 
           case 0 : printf("fat "); 
           case 1 : printf("hat "); 
           case 2 : printf("cat "); 
           default: printf("Oh no!"); 
       } 
       putchar('\n'); 
    } 
    return 0; 
}

Result


Related Tutorials