Foundation to Java Programming - The For Loop


Available Answers

  1. 1.

    Fill in the blanks.

    1. The for loop is an example of ____________ controlled loop.
    2. The _________ expression in a loop begins and ends with a semicolon.
    3. The __________ loop is usually used if the number of iteration is known.
    4. If there is only one statement to be executed in the body of the for loop, giving braces is ___________.
    5. If the loop doesn't contain a body, it is called an __________ loop.
  2. 2.

    State whether the following statements are True (T) or False (F).

    1. Multiple initialization is possible in a for loop.
    2. Updation in a for loop may be given inside the body for the loop.
    3. The for loop is an example of exit controlled loop.
    4. You cannot have multiple updation in a for loop.
    5. If the test expression in a for loop evaluates to false, the loop do not execute.
  3. 3.

    What is the output of the following program fragment:

    int i,s=0;
    for(i=1;i<=4;i++)
    {
    s=s+i;
    }
    System.out.println(s);
  4. 4.

    How many times will the following loop execute?

    int y;
    for(y=1,y<=7;y++)
    {
    y++;
    }
  5. 5.

    What will the following loop display?

    for(A=1;A<=7;A+=2);
    System.out.print(A+" ");
    System.out.println(A);
  6. 6.

    Find the errors in the given for loop.

    class x {
         static void main()
         {
            int s;
            for(s=1,s<=10,s++)
            {
               System.out.println(s)
            }
         }
    }
20 more answer(s) available.

Please login to post your comments.