someone, please answer this.

This lesson showed you the general form of the syntax for a for loop in JavaScript:for

(initialize counter; condition; update counter) {code block;}

What does each part do, and why is it necessary?

Answers

Answer 1

Answer: A loop will continue running until the defined condition returns false . ... You can type js for , js while or js do while to get more info on any of these. ... initialization - Run before the first execution on the loop. ... But it can be used to decrement a counter too. statement - Code to be repeated in the loop.

Explanation:


Related Questions

Implement the function printTwoLargest that inputs an arbitrary number of positive numbers from the user. The input of numbers stops when the first negative or zero value is entered by the user. The function then prints the two largest values entered by the user. If fewer than two distinct positive numbers are entered a message to that effect is printed instead of printing any numbers. Hint: Duplicates will cause problems. Try to make sure that you find a way to ignore them.

Answers

Answer:

The function in Python is as follows:

def printTwoLargest():

   chk = 0

   list1 = []

   num = int(input("Enter: "))

   while num > 0:

       for i in list1:

           if i == num:

               chk+=1

               break;

       if chk == 0:

           list1.append(num)

       chk = 0

       num = int(input("Enter: "))

   list1.sort()

   if len(list1) >= 2:

       print("Largest:", list1[-1])

       print("Second:", list1[-2])

   else:

       print("Length of list must be at least 2")

Explanation:

This defines the function

def printTwoLargest():

This initializes a check variable to 0

   chk = 0

This initializes an empty list

   list1 = []

This prompts the user for input

   num = int(input("Enter: "))

The following loop is repeated until input is 0 or negative

   while num > 0:

The following for loop checks for duplicate

       for i in list1:

           if i == num: If duplicate is found

               chk+=1 The check variable is set to 1

               break; And the for loop is exited

The input is appended to the list if the check variable is 0 (i.e. no duplicate)

       if chk == 0:

           list1.append(num)

This sets the check variable back to 0, for another input

       chk = 0

This prompts the user for another input

       num = int(input("Enter: "))

This sorts the list

   list1.sort()

This prints the two largest if valid user input is 2 or more

   if len(list1) >= 2:

       print("Largest:", list1[-1])

       print("Second:", list1[-2])

if otherwise, this prints that the length must be at least 2

   else:

       print("Length of list must be at least 2")

Other Questions
Which detail in Passage I introducesinformation irrelevant to Reagan'sargument? The moon is a sphere with radius of 959 km. Determine an equation for the ellipse if the distance of the satellite from the surface of the moon varies from 357 km to 710 km. x squared divided by 357 plus y squared divided by 710 equals 1 x squared divided by 1669 squared plus y squared divided by 1316 squared equals 1 x squared divided by 1316 squared plus y squared divided by 1669 squared equals 1 x squared divided by 710 plus y squared divided by 357 equals 1 Use the figure to complete the cross number puzzle Please answer the question CORRECTLY with a logical explanation. You will get brainliest guaranteed. What is the missing product in this reaction?2HCl + Ca(OH)2 ______ + 2H2O Are donkys actually donkys or are they horses?(My brother wants me to ask this) HELP ASAP NO LINKS OR ILL REPORT!!!!_____________What does Zeus plan to do to the mortals after they made an attack on the gods??? If an organism ingests 950.0 g of glucose (C6H12O6) in its lifetime, how many grams of carbon dioxide (CO2) will be released? (molar mass C6H12O6 = 180.156 g/mol) (molar mass CO2 = 44.009 g/mol) What are all of the Bandang Drum and Lyre instruments' names como conseguir novio en tres das? Where are most of the members of OPEC located?A. Northern EuropeB. AustraliaC. East AsiaD. The Persian Gulf A solid, uniform sphere of mass 2.0 kg and radius 1.8 m rolls from rest without slipping down an inclined plane of height 7.5 m. What is the angular velocity of the sphere at the bottom of the inclined plane your kitchen clock has a radius of 8 inches. you want to know how much it will cost to cover the outside edge of the clock in silver that costs $2.50 per inch. I need it fast please If f(x) = x 2 + 1 and g(x) = 3x + 1, find f(2) + g(3). a force of attraction between objects that is due to their masses and distance between objectsa. gravityb. weightc. mass Which statement about American sculpture of the late 1800s is true?Sculptures often showed English kings and queens.Sculptures were most often nonrepresentational.Sculptures by Daniel Chester French were popular. A triangle has side length measurements of 7 ft., 2 ft., and 5feet. Can this form a triangle? Explain why or why not. what question could be asked using the 6W about the first black president plz