Question
Asked Sep 17, 2019
3 views

What is the difference between a while loop and a for loop in javascript?

check_circle

Expert Answer

Step 1

Difference between while loop and for lo...

for loop
while loop
A while loop is used, when the user doesA for loop is used, when the user know about the
not know about the number of iterationsnumber of iterations needed.
needed
Syntax
while(condition)
{
Syntax:
for (initialization; condition; increment)
{
statement
lstatement
}
}
The loop variable must be incremented In for loop, the variable is initialized, checked, and
before the loop. If the user fails to
increment the loop variable, then the loopncremented in this specific order. All these
will not get terminate.
Еxample:
processes are performed inside this loop.
Example:
i=1
input 10
while-input)
for-1i-10i+
{
/code
lcode
}
help_outline

Image Transcriptionclose

for loop while loop A while loop is used, when the user doesA for loop is used, when the user know about the not know about the number of iterationsnumber of iterations needed. needed Syntax while(condition) { Syntax: for (initialization; condition; increment) { statement lstatement } } The loop variable must be incremented In for loop, the variable is initialized, checked, and before the loop. If the user fails to increment the loop variable, then the loopncremented in this specific order. All these will not get terminate. Еxample: processes are performed inside this loop. Example: i=1 input 10 while-input) for-1i-10i+ { /code lcode }

fullscreen

Want to see the full answer?

See Solution

Check out a sample Q&A here.

Want to see this answer and more?

Solutions are written by subject experts who are available 24/7. Questions are typically answered within 1 hour.*

See Solution
*Response times may vary by subject and question.
Tagged in

Engineering

Computer Science

Related Computer Science Q&A

Find answers to questions asked by student like you

Show more Q&A add
question_answer

Q: Write a program that contains 2 methods, main and printLine (10 points)1) The printLine method will ...

A: Declare required variables ‘first’, ‘second’ and ‘times’ which is used to store first character, sec...

question_answer

Q: how to write a function in python 3 that take a tuple t = (7,8,4,20,11) and returns a list which inc...

A: Note: The below program has been complied and executed in “repl.it” online complier

question_answer

Q: What is it when they say 4g or 5g phone network

A: The usage of 4G or 5G defines that the mobile phone includes 4G or 5G network for the communication....

question_answer

Q: Create the physical level ERD.  I believe my physical level ERD is missing several parts. However, t...

A: Hey.....The actual design of database can be represented  by  physical E- R   diagrams.Physical ERD ...

question_answer

Q: Load “Lock5Data” into your R console. Load “OlympicMarathon” data set in“Lock5Data”. This data set c...

A: First we install the Lock5Data package and then load the package. Then we load the library dplyr to ...

question_answer

Q: Consider the following grammar in BNF (start symbol is ) Which of the following sentences are in the...

A: Backus-Naur Form (BNF):BNF is a formal mathematical method to define the syntax of the programming l...

question_answer

Q: Use Java programming language Write a program that asks the user to enter 5 test grades (use an arra...

A: Note:Complete program is provided with all the required methods.Comments are provided for better und...

question_answer

Q: As an IT manager, what strategy would you have followed to avoid the failed implementation of ERP sy...

A: ERP system:It denotes software for business process management that permits an organization in using...

question_answer

Q: 2. What are ‘accelerated filers’ and how are they selected- revenue, # employee, etc.

A: If a company meets the following conditions at the fiscal year end, it is considered as accelerated ...