Question

2. (5pts.) What is a Count controlled loop? C++

2. (5pts.) What is a Count controlled loop? C++

Homework Answers

Answer #1

Count-controlled loops use a counter (also referred to as loop index) which countsspecific items or values and causes the execution of the loop to terminate when the counter has incremented or decremented a set number of times. Event-Controlled loops use an event to control the iteration of the loop.

LOOPING IN C++

The while statement is like the if statement in that it tests a condition. just like an if statement, the condition in a while statement can be an expression of any simple data type. In C++, any nonzero value is coerced to type Boolean true, and zero is coerced to type Boolean false. If the expression evaluates to false, then execution passes beyond the while loop; if it evaluates to true, than the code in the while loop executes once and then the conditional expression is once again evaluated. Each pass through the loop is called an iteration, and before each iteration there is a loop test.

The statement or group of statements to be executed each time through the loop is known as the body of the loop. The body of the loop must be enclosed in curly braces if contains more than one statement.

The condition that causes the loop to exit is the termination condition. There are two different types of loops, depending on what constitutes the termination condition. The first type of loop is the count-controlled loop, which is a loop that executes a specified number of times. The second type of loop is the event-controlled loop, which terminates when something has occurred inside the loop body. This sort of loop is used when working with variable data, such as user input, or searching the contents of a file.

A count controlled loop uses a variable called the counter or iterator in the loop test. Before we start the loop, we must initialize the counter variable, and in each iteration of the loop we must modify the counter in some way so that it reaches a termination condition.

#include <iostream>

using namespace std;

int main(void){

    int counter = 1;

    while(counter <= 10){
        cout  <<  "In the loop!"  <<  endl;    
        cout  <<  "Incrementing the counter variable..."  <<  endl;
        counter++;
        cout  <<  "End of the loop body!"  <<  endl;
    }    

    return 0;

}
Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0...
convert the while loop into for loop x = int(input('Enter initial value: ')) count = 0 if(x<1): print('Error') exit() print('Initial value is: ',x,' ',end='') while(x!=1): if(x%2==0): x=x/2 else: x=3*x+1 count+=1 if(x!=1): rint('Next value is: ',int(x),' ',end='') else: print('Final value ',int(x),', ',end='') print('number of operations performed ',int(count),' ',end='') break
The register that holds the count value in SHIFT, ROTATE, and LOOP is called : DX...
The register that holds the count value in SHIFT, ROTATE, and LOOP is called : DX CX BX AX
There are two basic forms of control system: open-loop and closed-loop. With closed loop there is...
There are two basic forms of control system: open-loop and closed-loop. With closed loop there is a feedback, a system containing a comparison element, a control element, correction element, process element and the feedback involving a measurement system. Figure below shows the layout of these elements in a generic closed loop system. Can you identify the following elements that might be present in a closed loop control system involving a thermostatically controlled furnace? In such a system, what would each...
Use an endless loop structure (with a sentinel escape) to count the number of digits in...
Use an endless loop structure (with a sentinel escape) to count the number of digits in any input integer. Sample output: Enter the integer ( -99 to exit) : 16                            16 has 2 digits                            Enter the integer ( -99 exit): 12345                            12345 has 5 digits                            Enter the integer (-99 to exit): -99 **Write program in JAVA**
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop...
8.36 Lab 8a: Count by 3 Introduction For this lab, you will use a while loop to complete the task. A while loop has this basic structure: /* variable initializations */ while (/*stop condition*/){ /* statements to be performed multiple times */ /* make sure the variable that the stop condition relies on is changed inside the loop. */ } Despite the structure of the while loop being different than that of a for loop, the concept behind it is...
Consider this program segment int count; for (count = 2; count < value; count ++) {...
Consider this program segment int count; for (count = 2; count < value; count ++) { if (nums[count] < anyNumber)             System.out.print (“ALWAYS”); } What is the maximum number of times that ALWAYS can be printed;
Using a for Loop visual c++ Summary In this lab the completed program should print the...
Using a for Loop visual c++ Summary In this lab the completed program should print the numbers 0 through 10, along with their values multiplied by 2 and by 10. You should accomplish this using a for loop instead of a counter-controlled while loop. Instructions Write a for loop that uses the loop control variable to take on the values 0 through 10. In the body of the loop, multiply the value of the loop control variable by 2 and...
Cell re-selection in LTE is: a. UE controlled b. Network controlled c. eNB controlled d. MME...
Cell re-selection in LTE is: a. UE controlled b. Network controlled c. eNB controlled d. MME controlled
Compute the following limits and show all your work: (a) 5pts A = limx→∞· 4x^2 −3/x^2...
Compute the following limits and show all your work: (a) 5pts A = limx→∞· 4x^2 −3/x^2 +11 lnx ¸ . (b) 5pts B = lim x→3+ (x−3)^3 ln(x−2) . Hint for (b): Taking the natural logarithm of “both sides” will help
Assume that you would like to invest in a company.Required:a)What is your cost object(5pts)? (Do not...
Assume that you would like to invest in a company.Required:a)What is your cost object(5pts)? (Do not define cost object; please write down the item or service that you want to produce and sell)b)What is the Direct Materialof your product or service(5pts)?c)What are the overhead costs of your product or service(5pts)?d)Assume that you would liketo assign overhead costs to your product or service. Which method you would prefer to use for assigning overhead costto your product or service(In other words,how do...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT