Question

In: Computer Science

What are the key constructs required to create a loop? Identify two scenarios that may require...

What are the key constructs required to create a loop? Identify two scenarios that may require two different types of loops. Be sure to provide specific details for each scenario that illustrate why the different types of loops are required.

Solutions

Expert Solution

In most languages we have 3 kinds of basic loops.
1. For loop
2. While loop
3. do-while loop

For loop and while loop are identical and interchangeable with no or little effort. These loops are entry control loops, that is loop condition is verified on entering. Since the condition is checked while entering the loop, it may happen that the body of the loop is not even executed.

Application of for loop:
Enter n, and print all numbers more than n but less than 100

in such cases is n > 100, no number is printed.

The other kind of loop is do-while loop. This loop is exit control loop, that is the condition is checked while exiting the loop. Since ther is no check while entering the loop, the body of the loop will be executed atleast once. While loop can be used as a do-while loop by intruducing a new variable.

Application of do-while loop:

Enter 1 to exit loop.

in such case the number is accepted within the body of the loop. and the condition is checked whille exiting the loop


Related Solutions

Identify two key design choices firms may be required to make when deciding on the structure...
Identify two key design choices firms may be required to make when deciding on the structure of their firm. Explore how their choices could impact the conduct and performance of the firm. You should use examples to illustrate your answer
Create a scenario for two variables that may be related. Identify a sample dataset (sample size...
Create a scenario for two variables that may be related. Identify a sample dataset (sample size n=10) and using it calculate covariance and correlation values. Interpret the relationship.
c) Create a scenario for two variables that may be related. Identify a sample dataset (sample...
c) Create a scenario for two variables that may be related. Identify a sample dataset (sample size n=10) and using it calculate covariance and correlation values. Interpret the relationship.
What is a closed loop supply chain and what are what are the key activities in...
What is a closed loop supply chain and what are what are the key activities in a closed loop supply chain? Briefly discuss also one example of a real life closed loop supply chain.
Identify policy response pathways to the chosen disaster and key factors that modulated the contrasting scenarios...
Identify policy response pathways to the chosen disaster and key factors that modulated the contrasting scenarios (ie., social, economic, environmental factors etc.)? Use references
Identify the key financial statements required by the IFRS for reporting to stockholders.
Identify the key financial statements required by the IFRS for reporting to stockholders.
What do the different growth models identify as the key determinants of economic growth? Identify two...
What do the different growth models identify as the key determinants of economic growth? Identify two key limitations of the neoclassical growth model in explaining contemporary developing country experiences. Finally, compare and contrast Neoclassical, Marxian and Keynesian economic theories.
Identify the flaws in the reasoning of the researchers in the following two scenarios, and discuss...
Identify the flaws in the reasoning of the researchers in the following two scenarios, and discuss these flaws as completely as you can given the information provided in the question. (a) Five hundred students at a randomly selected big-city elementary school are given a 25-question survey that they are to return the next day after their parents have filled it out. One of the questions asked of parents is, “Does your work schedule make it difficult to spend after-school time...
Identify and discuss two reasons why employees may create budgetary slack and how an organisation can...
Identify and discuss two reasons why employees may create budgetary slack and how an organisation can reduce the problems caused by budgetary slack?
C++ Create an ArrayBag template class from scratch. This will require you to create two files:...
C++ Create an ArrayBag template class from scratch. This will require you to create two files: ArrayBag.hpp for the interface and ArrayBag.cpp for the implementation. The ArrayBag class must contain the following protected members: static const int DEFAULT_CAPACITY = 200; // max size of items_ ItemType items_[DEFAULT_CAPACITY]; // items in the array bag int item_count_; // Current count of items in bag /** @param target to be found in items_ @return either the index target in the array items_ or...
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT