Question

What are three types of loops discussed in Chapter 5? What are differences and similarities among...

What are three types of loops discussed in Chapter 5? What are differences and similarities among them? What loop you should use in a particular kind of applications? Please participate this discussion.
the language is java.
0 0
Add a comment Improve this question Transcribed image text
Answer #1

The three types of loops available in java are:

  • while loop
  • do while loop
  • for loop

While loop can be used as condition controlled loop(Entry controlled loop) , the loop body executes until the condition is true , and the loop exits when condition is false.

we can use this loop when we dont know how many iterations are required for loop ahead.

For example, when finding a reversal of number, The number is continuously divided by 10 until number becomes 0.

-------------------------------------

do..while loop

This loop executes atleast one time, even the condition is false, This loop is called exit controlled loop.

After every iteration, at the end it checks the condition , if the condition is false then the loop executes.

For exmple :the loop continues until we enter negative number

-----------------------------------------------

for loop

This is used as counter controlled loop, the loop statement contains initialization, condition and increment or decrement.

This loop is used when number of iterations are known ahead.

For example, when we want to run loop for 10 times, counter is initialized to one and runs for 10 times.

Add a comment
Know the answer?
Add Answer to:
What are three types of loops discussed in Chapter 5? What are differences and similarities among...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT