Question

In: Computer Science

In pseudocode, consider the DOWHILE repetition control structure. Control passes to the next statement after the...

In pseudocode, consider the DOWHILE repetition control structure. Control passes to the next statement after the delimeter ENDDO (and no further processing takes place within the loop) when which of the following occurs? a condition p is found to not evaluate to true or false a condition

p is found to be true

a condition p is found to null

None of the other answers are correct

a condition p is found to be false

Solutions

Expert Solution

ans) a condition p is found to be false

explaination:

Like while the do-while loop execution is also terminated on the basis of a test condition. The main difference between a do-while loop and while loop is in the do-while loop the condition is tested at the end of the loop body, i.e do-while loop is exit controlled whereas the other two loops are entry controlled loops.

Syntax:

do
{
   // loop body

   update_expression;
} 
while (test_expression);

The various parts of the do-while loop are:

  1. Test Expression: In this expression we have to test the condition. If the condition evaluates to true then we will execute the body of the loop and go to update expression. Otherwise, we will exit from the while loop.
    Example:
    i <= 10
  2. Update Expression: After executing the loop body, this expression increments/decrements the loop variable by some value.
    Example:
    i++;

How does a do-While loop executes?

  1. Control falls into the do-while loop.
  2. The statements inside the body of the loop get executed.
  3. Updation takes place.
  4. The flow jumps to Condition
  5. Condition is tested.
    1. If Condition yields true, goto Step 6.
    2. If Condition yields false, the flow goes outside the loop
  6. Flow goes back to Step 2.

Flow Diagram do-while loop:

// C++ program to illustrate do-while loop 

#include <iostream> 
using namespace std; 

int main() 
{ 
        // Initialization expression 
        int i = 2; 

        do { 
                // Loop body 
                cout << "Hello World\n"; 

                // Update expression 
                i++; 

        } 
        // Test expression 
        while (i < 1); 

        return 0; 
} 

Output:

Hello World

Dry-Running Example 1:

1. Program starts.
2. i is intialised to 2.
3. Execution enters the loop
  3.a) "Hello World" gets printed 1st time.
  3.b) Updation is done. Now i = 2.
4. Condition is checked. 2 < 2 yields false.
5. The flow goes outside the loop.
// C program to illustrate do-while loop 

#include <stdio.h> 

int main() 
{ 
        // Initialization expression 
        int i = 1; 

        do { 
                // Loop body 
                printf("%d\n", i); 

                // Update expression 
                i++; 

        } 
        // Test expression 
        while (i <= 5); 

        return 0; 
} 

Output:

1
2
3
4
5

Related Solutions

What are the advantages and disadvantages of using a repetition structure in an application?
What are the advantages and disadvantages of using a repetition structure in an application?
pseudocode The main( ) program passes these integer values as arguments to the findMax( ) method...
pseudocode The main( ) program passes these integer values as arguments to the findMax( ) method for further processing. The main program receives one result back from findMax( ) method and displays the maximum of these three integer values. The findMax( ) method simply receives three integer values from the main program and finds the maximum of three integers and returns one value back to the caller (in this case the main application).
“A protein’s function and control is determined by its structure.” Critically discuss this statement, with a...
“A protein’s function and control is determined by its structure.” Critically discuss this statement, with a focus on how the use of computers and databases can be used to better understand how a protein works in a cell.
Consider the infinite repetition of the game below. For LRA payoffs, find the full set of...
Consider the infinite repetition of the game below. For LRA payoffs, find the full set of (long-run) equilibrium payoffs. Find the set of discount factors λ ε (0,1) for which cooperation (with 6,6 as payoffs) can be sustained by reversion to the one-shot Nash equilibrium as a threat.
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ......
Implement the following pseudocode in Python Consider the following pseudocode for a sorting algorithm: STOOGESORT(A[0 ... n - 1]) if (n = 2) and A[0] > A[1] swap A[0] and A[1] else if n > 2 m = ceiling(2n/3) STOOGESORT(A[0 ... m - 1]) STOOGESORT(A[n - m ... n - 1]) STOOGESORT(A[0 ... m - 1])
Identify an internal control structure and describe an effective internal control structure, relating to accounting and...
Identify an internal control structure and describe an effective internal control structure, relating to accounting and preparing accurate financial statements.
list the structure and fluids that light passes through from the cornea to the retina?
list the structure and fluids that light passes through from the cornea to the retina?
5.25. The following pseudocode (next page) is a correct implementation of the producer/consumer problem with a...
5.25. The following pseudocode (next page) is a correct implementation of the producer/consumer problem with a bounded buffer: Labels p1, p2, p3 and c1, c2, c3 refer to the lines of code shown above (p2 and c2 each cover three lines of code). Semaphores empty and full are linear semaphores that can take unbounded negative and positive values. There are multiple producer processes, referred to as Pa, Pb, Pc, etc., and multiple consumer processes, referred to as Ca, Cb, Cc,...
Consider the following statement: When designing a data structure, it is important to distinguish between what...
Consider the following statement: When designing a data structure, it is important to distinguish between what the characteristics and operations of the data structure are versus how they can be implemented. (a) Explain why defining the ADT as a Java interface and defining classes to implement the interface is consistent with the above statement. (b) Describe how the setup in part (a) is an example of polymorphism and provide a specific example of how polymorphism can be used to make...
Objectives To use selection statements To use repetition statement Problem Specification Skip by 7’s and 9’s...
Objectives To use selection statements To use repetition statement Problem Specification Skip by 7’s and 9’s 1. Generate n numbers between -100 and 100. 2. If the value is multiple of 7 or 9, replaced by * 3. Then change to new line after the multiple of 7 or 9 is appeared Design Specification Use if Use if … else Use while Example:
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT