C Programming Language For Loop Quizzes


  • 1. What are the three general types of looping structures?






  • 2. What is the output of the following program fragment?

    for ( int j = 0;  j <  5; j++ )
    {
      System.out.print( j + " " );
    }
    System.out.println( );





  • 3. Output of following program?

    for ( int j = 10;  j >  5; j-- )
    {
      System.out.print( j + " " );
    }
    System.out.println( );
    





  • 4. What must the test be so that the following fragment prints out the integers 5 through and including 15?

    for ( int j = 5;  ________ ; j++ )
    {
      System.out.print( j + " " );
    }
    System.out.println( );





  • 5. What must the change be so that the following fragment prints out the even integers 0 2 4 6 8 10?

    for ( int j = 0; j <= 10; _______   )
      System.out.print( j + " " );
    System.out.println( );
    





  • 6. What must the initialization be so that the following fragment prints out the integers -3 -2 -1 ?

    for ( _______; j < 0; j++    )
      System.out.print( j + " " );
    System.out.println( );





  • 7. What is the output of this C code?

    for ( int j = 5;  j > -5; j-- )
      System.out.print( j + " " );
    
    System.out.println( );
    





  • 8. Which of the following will print the value 2 for the below program ?

    int count = 0;
    for ( ;  count < 9; ++count )
      System.out.print( count + " " );
    
    System.out.println( );
    





  • 9. What is the output of this code?

    for ( int count = 0;  count < 9;   )
      System.out.print( count + " " );
      count++ ;
    System.out.println( );
    





  • 10. What is the output of this C code?

    int j;
    for ( j = 0;  j < 5;   )
    {
      System.out.print( j + " " );
      j++ ;
    }
      
    System.out.println( );