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
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 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 =...
(a) Provide a detailed explanation of the (signed) integer overflow. (b) Write C++ program that displays...
(a) Provide a detailed explanation of the (signed) integer overflow. (b) Write C++ program that displays the table of function 2n . This is an integer value that you must compute using multiplication, and the use of power function pow(2.,n ) is not permitted. Display lines that contain n and 2n for n=0,1,2,3,… and show all lines that contain correct values. Stop displaying before the occurrence of the integer overflow. Your program must work on any computer and for any...
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.
I'm confused about upper bound and worst case are different. Can you provide an explanation/examples to...
I'm confused about upper bound and worst case are different. Can you provide an explanation/examples to help me separate these two concepts in my mind?
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
Please provide an explanation, traits and examples of complementary needs theory.
Please provide an explanation, traits and examples of complementary needs theory.
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.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT