Iterative Constructs in Java

Multiple Choice Questions

  1. When the statements are repeated sequentially for a number of times in a program, the construct is known as:
    (a) iteration
    (b) sequence
    (c) selection
    (d) none
  2. Which of the following statement is an exit-controlled loop?
    (a) for
    (b) while
    (c) do-while
    (d) if-else
  3. Which of the following loop does not execute even once if the condition is false in the beginning?
    (a) do-while
    (b) while
    (c) for
    (d) nested loop
  4. To execute a loop 10 times, which of the following statement satisfies?
    (a) for(i = 6;i <= 26; i = i + 2)
    (b) for(i = 3; i <= 30; i = i + 3)
    (c) for(i = 0; i < 10; i = i++)
    (d) all of the above
  5. Which of the following statement uses multiple branches?
    (a) loop
    (b) continue
    (c) switch
    (d) break
  6. Which of the following loop checks the condition first and then execution begins?
    (a) do-while
    (b) do
    (c) while loop
    (d) for
  7. To find the sum of whole numbers up to 10, a loop runs:
    (a) once
    (b) ten times
    (c) eleven times
    (d) any number of times
  8. How many times the loop: for(i = 1;; i++) will execute, if there is no statement to terminate the loop?
    (a) 1
    (b) 0
    (c) infinite
    (d) none
  9. Which of the following statements uses a case called default?
    (a) do-while
    (b) while
    (c) switch
    (d) all of the above
  10. A loop statement is given as:
    for(i = 10; i < 10; i++){
    statement
    }
    For how many times will the given loop statement be executed?
    (a) never
    (b) 1 time
    (c) 10 times
    (d) infinite

Answer the following questions:

  1. What do you understand by iterative process? How can it be resolved by using loop?
    It is a construct in which a statement or a set of statements are repeatedly executed till the condition is satisfied.
    It can be resolved by using loops because it allows us to easily specify what task needs to be executed and for how many times.
  2. Explain for loop with an example.
    The for loop is an entry-controlled loop which is suitable when the number of iterations is fixed.
    Example:
    for(i = 1; i <= 10; i++){
    System.out.println(“Google Pay”);
    System.out.println(“Money made simple, by Google”);
    }
  3. Name the different types of loop statements.
    Different types of loop statements are:
    a) for loop
    b) while loop
    c) do-while loop
  4. What are the parameters needed to create a for loop?
    Following are the parameters needed to create a for loop:
    a) Initial value for the counter variable.
    b) Test condition to terminate the loop at a certain point.
    c) Update expression to modify the counter variable after each iteration.
    d) Loop body to be executed in each iteration.
  5. Define the following with their constructs:
    (a) Entry-controlled loop: Condition is checked before executing the loop body. Constructs: for loop and while loop.
    (b) Exit-controlled loop: Condition is checked after executing the loop body. Construct: do-while loop.
  6. Write down the general format of:
    (a) for loop
    for(initial value; test condition; update){
    task
    }
    (b) do-while loop
    do{
    task
    }while(test condition);
    (c) while loop
    while(test condition){
    task
    }
  7. What is the purpose of using:
    (a) break statement: It is used for forceful termination of a loop block.
    (b) continue statement: It is used to skip the current iteration of the loop, and move to the next iteration.
  8. What do you understand by inter-conversion of loops?
    Inter-conversion of loops is about converting one form of repetitive structure to another form to model our program logic as per our convenience.
  9. What are the different ways to inter-convert the loops? Name them.
    Following are the different ways to inter-conversion of loops:
    a) for loop to while loop
    b) for loop to do-while loop
    c) do-while loop to while loop
    d) do-while loop to for loop
    e) while loop to do-while loop
    f) while loop to for loop
  10. Define the following:
    (a) Finite loop: Loop in which the statements run for a fixed number of times.
    (b) Delay loop: Loop that is used to create a delay in the execution by creating a null loop.
    (c) Infinite loop: Loop in which a looping structure will never come to an end, created by omitting one or more parameters.
    (d) Null loop: Loop which doesn’t include any statement to be repeated.
  11. Distinguish between:
    (a) for and while loop
    The for loop is a suitable choice when the number of iterations is fixed, whereas the while loop is a suitable choice when the number of iterations is not fixed.
    (b) while and do-while loop
    The while loop is entry-controlled, whereas the do-while loop is exit-controlled.
  12. State one difference and one similarity between while and do-while loop.
    Similarity: Both while and do-while loops are used when the number of iterations is not fixed.
    Dissimilarity: The while loop is entry-controlled, but the do-while loop is exit-controlled.
  13. State one similarity and one difference between while and for loop.
    Similarity: Both while and for loops are entry-controlled loops.
    Dissimilarity: The for loop is a suitable choice when the number of iterations is fixed. The while loop is a suitable choice when the number of iterations is not fixed.
  14. Give two differences between step loop and continuous loop.
    Step loop is a system of creating a loop where the control variable is updated by a given value after each iteration. The loop starts with an initial value, repeats execution of the statements by updating the value with the given step.
    Continuous loop is a type of looping structure in which the control variable is updated only by 1 after each iteration. The loop is terminated as soon as the control variable exceeds the last limit.

1 thought on “Iterative Constructs in Java”

Leave a Reply

%d bloggers like this: