Question

In: Computer Science

Provide explanation about Iterations. Give examples and write a program.

Provide explanation about Iterations. Give examples and write a program.

Solutions

Expert Solution

Iterations are simply said to be executing some set of statements continuously for 'n' number of times or the condition is encountered.

Cycle of instructions are performed in a repeated manner called 'loops'.

There are two types of iteration:

1)Count controlled iterations: This iteration is used for repeat the statements or steps a specific number of times. In this iteration you already know the how many iterations it takes.

for example, FOR loop. For loop is comes under this count controlled iterations.

example in python language:

n=5

for i in range(0,n):

       print(i)

output: 0,1,2,3,4

2)Condition controlled iterations: This iteration is used for repeating the statements continuously until the condition is satisfied. In this case the number of iterations are unknown. It follows the condition is true or false. If true, statement is executed otherwise not executed.

for example, While loops comes under this condition controlled iterations.

examples in python language:

n=6

a=1

while(a<n):

       print(a)

       a=a+1

output: 1 2 3 4 5


Related Solutions

When is it necessary to use a vacuum distillation? Give some explanation and provide examples
When is it necessary to use a vacuum distillation? Give some explanation and provide examples
Write a C++ program for Euclids Algorithm that keeps track of the number of iterations (%...
Write a C++ program for Euclids Algorithm that keeps track of the number of iterations (% & loop) 1. Euclid’s Algorithm An alternative of the Euclidean algorithm for finding greatest common divisors (GCD) is repeatedly performing the modulo operation on two numbers until the remainder is 0. Here is the pseudocode for find the GCD of two positive numbers a and b using the Euclidean algorithm :while b ≠ 0 temp = b b = a mod t a =...
Give 2 different examples of an infinite dimensional vector space and provide an explanation in possible....
Give 2 different examples of an infinite dimensional vector space and provide an explanation in possible. This is a review question for linear algebra and I am trying to better understand the concept. Thank you!
Write an essay about: what is consumer behavior? Give examples of the types of questions about...
Write an essay about: what is consumer behavior? Give examples of the types of questions about consumer behavior that marketers investigate
Give good examples and write in complete sentences. Provide a definition and an example of each...
Give good examples and write in complete sentences. Provide a definition and an example of each of Marcia’s four identity statuses: a) identity diffusion (what the text described as role confusion); b) identity foreclosure; c) identity moratorium, and d) identity achievement.
Give two practical examples for following concepts/principles. Also write where these are used with brief explanation:...
Give two practical examples for following concepts/principles. Also write where these are used with brief explanation: (a) Centroid (b) Moment of inertia (c) General plane motion (d) Work energy principle (e) Impulse-momentum principle
Write a paper about World Economy and International Trade. Give facts and figures using examples. Give...
Write a paper about World Economy and International Trade. Give facts and figures using examples. Give your view on both of them. Kindly write around 3-4 pages.
Please provide an explanation, traits and examples of complementary needs theory.
Please provide an explanation, traits and examples of complementary needs theory.
Research on Alibaba and write a few sentences about ( please give examples when needed) (a)...
Research on Alibaba and write a few sentences about ( please give examples when needed) (a) Description of business model (b)Competitive advantage(s): (c) Growth opportunities: (d) Catalyst(s):
please provide a detailed explanation of the social learning theory (Bandura) and examples
please provide a detailed explanation of the social learning theory (Bandura) and examples
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT