English Deutsch Français Italiano Español Português 繁體中文 Bahasa Indonesia Tiếng Việt ภาษาไทย
All categories

can I please,get some help in Java programming language,I need help with loops.while loop, for loop and the do loop.I'm falling behind in class so if anyone could spare the time to give me a detailed explanation on loops cause i'm not getting it and I have an exam coming up.thanks

2006-12-13 14:23:32 · 5 answers · asked by Anonymous in Computers & Internet Programming & Design

5 answers

Let me ask you a question. Why do you think that anything anyone writes here will be any better than your textbook? I'm not being snide here, it's a serious question. It seems to me that even if someone takes the considerable time to write text explaining the fairly broad topic of loops in java, it will be a first draft.

In contrast, if you just read your book, you'll be reading carefully constructed text that's been through several revisions, tested with many classes full of students, and just generally tested in an educational environment. Why do you think Yahoo Answers is going to beat that?

The truth is, you just need to sit down and read the book. Take the earbuds out, find a comfortable chair in a well-lit spot at the library or home, and start reading. It's really that simple. Good luck.

2006-12-13 14:30:46 · answer #1 · answered by arbeit 4 · 1 0

OK man, calm down then relax. :)
There's usually 2 kinds of loops in programming language: countable, and uncountable. Countable loops means that you can know exactly how many loops will run, and uncountable loops means for you how many times the loops will run (but you know the condition to stop the loops).
For countable loops, you can use the FOR LOOPS to implement it.
Ex:
for(int i=0; i<100; i++)
{do thing in loop}
Notes here: remember not to change the value of i inside the loops unless you know what to do ;), or you will get unexpected result.
For uncountable loops, you can use the WHILE LOOPS and DO WHILE LOOPS.
ex:
while (a { do something here}
this will do something while the condition is still true (ab).
The different between WHILE and DO WHILE here is the DO WHILE loops will do at least 1 loop, while the WHILE loops may do at least no loop.
ex:
while(a {do something}

do
{do something}
while (a
If a>b, the loop in while loop do 0 times, but in the do while loop, it will do 1 times.
Good luck and hope you can get good mark on next exams.

2006-12-13 14:43:14 · answer #2 · answered by -=MISA Returns=- 1 · 2 0

loops perform iteration, basically meaning they complete a sequence of instructions until a sentinel (a loop stopper if you will) is reached. There are several different types of loops, such as a while loop, which will keep going while a statement is TRUE, a do while loop (which is VERY similar to a while loop) which does a set of instructions until a condition is reached,the for loop in which you have asked about is typically used WHEN YOU KNOW EXACTLY WHEN TO STOP THE LOOP. I will provide an example below of a for loop.

for (int sentinel = 0; sentinel < maxvalue; sentinel++)

Basically what this is saying for (declare variable int sentinel and put in the value as 0; loop until sentinel is greater than max value;each time the loop completes I want to add 1 to sentinel.

If you have more questions feel free to send me a message.

2006-12-13 14:29:40 · answer #3 · answered by D 4 · 0 0

I am a Visual BASIC programmer...I don't do Java, but you might check out http://www.pscode.com - it has great stuff in all different programming languages.

2006-12-13 14:34:22 · answer #4 · answered by Richard H 7 · 0 0

Not too sure about the code. When I need some, I go here:

http://javascript.internet.com/

2006-12-13 14:26:17 · answer #5 · answered by Robert C 3 · 0 0

fedest.com, questions and answers