LOOPS

Hi guys, I really understand loops and how they work, though its not clear to me why would you use a loop when coding an applicationi just want to get some examples on the most common uses of this feature
[218 byte] By [charles0712a] at [2007-11-27 9:21:53]
# 1
THE BOOK OR THE PROFESSOR DOESN'T SHOW ANY REAL LIFE EXAMPLES AND I REALLY WANT TO UNDERSTAND THISMessage was edited by: charles0712
charles0712a at 2007-7-12 22:16:00 > top of Java-index,Java Essentials,New To Java...
# 2

Their use is so ubiquitous as to defy the imagination. Any time you want to count out anything, programmatically, you'll probably be using a for loop. If you go through some of the sun tutorials, you will find a page where you can download the sample code from the tutorial. If you open any one of these code files I'll bet you will have a 50% or greater chance of finding a for loop. I'd study these.

petes1234a at 2007-7-12 22:16:00 > top of Java-index,Java Essentials,New To Java...
# 3
Will do so, thanks buddy!!
charles0712a at 2007-7-12 22:16:00 > top of Java-index,Java Essentials,New To Java...
# 4

Give each player a turn.

Keep getting user input until user enters "quit."

Read each line in a file.

Keep processing chat messages until user signs off.

List out each student's name and grade.

Compute the average of a bunch of values.

...and so on and so on and so on.

Any time you're performing the same operations on different data, or repeating something until some stopping condition, you're using a loop.

You use loops every day in your real life.

You keep taking another step until you get to your classroom.

You keep drinking until that bottle of beer is empty, and you keep getting new bottles until the fridge is empty. (That's a nested loop.)

You keep hitting channel-up until you find a show you like.

... and so on and so on and so on.

jverda at 2007-7-12 22:16:00 > top of Java-index,Java Essentials,New To Java...
# 5
> You use loops every day in your real life.I don't. Divine people like me use tail recursion. Loops are for peasants. ;-)kind regards,J(o(s))
JosAHa at 2007-7-12 22:16:00 > top of Java-index,Java Essentials,New To Java...
# 6

> > You use loops every day in your real life.

>

> I don't. Divine people like me use tail recursion.

> Loops are for peasants. ;-)

>

> kind regards,

>

> J(o(s))

void drinkRemainingGrolsch(List<Grolsch> precious) {

if (precious.isEmpty()) {

precious.restock();

}

drink(precious.get(0));

drinkRemainingGrolsch(precious.subList(1,precious.size()));

}

jverda at 2007-7-12 22:16:00 > top of Java-index,Java Essentials,New To Java...
# 7
Jeff, you forgot this lineSystem.out.println("BUUUUUUUUUUUUUUUUUURP!");
floundera at 2007-7-12 22:16:00 > top of Java-index,Java Essentials,New To Java...