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?
“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.
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])
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.
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?
Write pseudocode (3 Marks) and program structure (4 Marks) for the problem given below; In a...
Write pseudocode and program structure (4 Marks) for the problem given below; In a college, students are awarded a pass grade if their total mark is between 50-59, credit grade if the mark is between 60-69, distinction for marks between 70-79. High distinction if the mark is above or equal to 80 and fail if the mark is below 50.
4. Rewrite the following pseudocode segment using a loop structure in the specified languages: k =...
4. Rewrite the following pseudocode segment using a loop structure in the specified languages: k = (j + 13) / 27 loop:       if k > 10 then goto out       k = k + 1       i = 3 * k - 1       goto loop out: . . . a. C++ b. Python c. Ruby Assume all variables are integer type. Discuss the relative merits of the use of these languages for this particular code.
Use the following information to answer the next two questions. Consider the after-tax cash flows below:...
Use the following information to answer the next two questions. Consider the after-tax cash flows below: Year 0 1 2 3 4 Cash Flow -$75,000 $5,100 -$1,100 $498,000 -$272,000 The required rate of return is 12 percent. Find an internal rate of return (IRR) for these cash flows. Should you use the IRR you calculated in the previous question to decide whether the project is acceptable? Explain show work please
Selection/Conditional Structure: Create a flowchart and pseudocode for the problem below: Juan dela Cruz Restaurant is...
Selection/Conditional Structure: Create a flowchart and pseudocode for the problem below: Juan dela Cruz Restaurant is offering a 20% discount to all customers whose last name is also dela Cruz. Input the last name of the customer and the total amount due to the customer and then output the amount to be paid. (C++ Program, choose only the LAST NAME)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT