answersLogoWhite

0


Best Answer

Think of a Javascript loop as a loop in a rollercoaster, which, as you know, makes you go back to the place you started the loop, and then continue. Javascript allows you to create sections of code that make the program handler to go back to the point specified, so instead of copying out a functions directions twice, you can tell the program to reference that section of code for the instructions, and then jump back to where it was.

User Avatar

Wiki User

12y ago
This answer is:
User Avatar
More answers
User Avatar

Wiki User

11y ago

Firstly, do not call it 'java script' - such a phrase hints on a much stronger relation to java than javascript has. It is one word.

To answer your question, though, there are multiple types of loops because different loops do different things - making syntax more friendly for the user, and ensuring better efficiency in the underlying engine.

For example, the do{}while() loop runs AT LEAST once, where as the while(){} loop may not run at all if the conditions aren't satisfied. Yes, it's possible to write a while(){} loop to do the same thing as a do{}while() loop, but your code will be messier and less efficient because you'd be creating extra variables by necessity.

The for(){} loop is just a while loop with an added instantiation command and an added post-loop-adjustment command. This has pure syntax benefits in most javascript engines. It'd just get messy otherwise.

This answer is:
User Avatar

Add your answer:

Earn +20 pts
Q: Why does java script support more than one type of loop?
Write your answer...
Submit
Still have questions?
magnify glass
imp
Continue Learning about Engineering

Why java applet is executed faster than java script?

The java applet is in the java language and is run local to your computer, java script is in the language java script, this can be run local to server or computer. Java and java script are to different languages that run two different ways.


In java what is empty statement.Explain its usefulness?

An empty statement in Java is just that: a statement with nothing in it. There are typically two ways to represent this:A single semicolon ;An empty block {}The usefulness of this type of statement is limited. The main use that I can think of is to fulfill the statement required for a loop structure.Here is an example that I recently used:while (sf(++n) != i);This loop will constantly call the method sf with increasing values of n until the return value of sf(n) is equal to i. Each loop in Java must have some code to execute in the loop body. In this case, all necessary work is done in the condition, and so the mandatory loop body is an empty statement.While there may be other (more clear) ways of writing this bit of code, this is an example of where that empty statement can be used.


How improve knowledge of Java script?

Simple- Just code and code more. You could grasp every concept of programming language by reading but never really learn it without coding.


Write a java program to print the following output using the for loop 1 2 2 3 3 3 4 4 4 4 5 5 5 5 5?

12345 1234 123 12 1


Why is java's portability better than c plus plus?

As we know that java is a plateform independent language and the main advantage of java is that it can support to any operating system and can be executed to any machines without any modifications.Due to the use of class in java it has become more easier to understand the program compared to c plus plus.Hence,java is portable than c plus plus

Related questions

Why java applet is executed faster than java script?

The java applet is in the java language and is run local to your computer, java script is in the language java script, this can be run local to server or computer. Java and java script are to different languages that run two different ways.


How does Java Script enhances webpages?

Java Script allows client side modifications. In simple terms the websites which let you change the look and feel, drag & drop items, have good animations, image sliders, slideshows are more or less being done using java script. Ofcourse other languages and technologies are used but java script is the most commonly used in those scenarios.


What language are the android phones written in?

Google's Android platform uses Java (not Java Script) as it's programming language. You can find out more about how to start at developer.android.com. You can also download their SDK there.


What is certification and the importance of certifiction of javascript?

Java Script alone has no value. It has to be used in association with various server side technologies and other languages. There are certifications available on java script but it would be more prudent to get certified in industry recognized certifications primarily on server side technologies.


Is the game RuneScape bad for your computer?

Not at all as long as you have Java script already downloaded. There could be more, it slowed down my computer.


Is there any way to add items in history in java-script?

If you're in HTML 5 then the history.pushState() method can be used to add an item into the history. Not all the browsers support the method (yet.) You can find out more over at Mozilla (see related link.)


What are the alternatives of javascript?

There are some: HTML, which isn't really an alternative, but is another, simpler script-writing language, Java, which is much more complicated and can also work for stuf offline, and Python which is like Java. J0E


What can be added to java script to make the code more readable?

Comments would be the main thing. Using sensible variable names can also help.


What are the alternatives to inheritence in java?

Java does not support multiple inheritance; a subclass cannot have more than one parent. Java compensates for this with interfaces. A class can implement multiple interfaces, but can only extend one class.


In java what is empty statement.Explain its usefulness?

An empty statement in Java is just that: a statement with nothing in it. There are typically two ways to represent this:A single semicolon ;An empty block {}The usefulness of this type of statement is limited. The main use that I can think of is to fulfill the statement required for a loop structure.Here is an example that I recently used:while (sf(++n) != i);This loop will constantly call the method sf with increasing values of n until the return value of sf(n) is equal to i. Each loop in Java must have some code to execute in the loop body. In this case, all necessary work is done in the condition, and so the mandatory loop body is an empty statement.While there may be other (more clear) ways of writing this bit of code, this is an example of where that empty statement can be used.


Write a program in java to find factorial of a number?

I suggest to use a for loop, more or less like this (assuming the parameter is "n"): product = 1; for (int i = 1; i <= n; i++) { product *= i; }


How improve knowledge of Java script?

Simple- Just code and code more. You could grasp every concept of programming language by reading but never really learn it without coding.