How JustAnswer Works:
  • Ask an Expert
    Experts are full of valuable knowledge and are ready to help with any question. Credentials confirmed by a Fortune 500 verification firm.
  • Get a Professional Answer
    Via email, text message, or notification as you wait on our site. Ask follow up questions if you need to.
  • 100% Satisfaction Guarantee
    Rate the answer you receive.
Ask ATLPROG Your Own Question
ATLPROG, Computer Software Engineer
Category: Programming
Satisfied Customers: 7677
Experience:  MS in IT.Several years of programming experience in Java C++ C C# Python VB Javascript HTML
Type Your Programming Question Here...
ATLPROG is online now
A new question is answered every 9 seconds

Explain when you would use a while loop rather than a for

Customer Question

Explain when you would use a "while" loop rather than a "for" loop and vice versa.
Provide an example of one such instance. How are looping statements different from
selection statements?
Submitted: 8 years ago.
Category: Programming
Expert:  lifesaver replied 8 years ago.
Which programming language are you using or you just need psudocode examples..
Customer: replied 8 years ago.
I am using JDK 6 upgrade 13 but I need psudocode examples.
Customer: replied 8 years ago.

Can you also help me with this question?


I did the step by step instruction of toasting bread but he wants the refinement steps.


This my answer:

Algorithm for making toast

1. Get bread from bread pan.

2. Get butter or jelly out of refrigerator
3. Get plate out of cupboard
4. Get butter knife out of drawer
5. Plug toaster in
6. Insert bread into toaster
7. Turn toaster on
8. After toasting is completed, remove bread from toaster and place on plate
9. With butter knife, spread butter or jelly on toast

Algorithms is a formula or set of steps for solving a particular problem. Algorithms provide an organized structure to our daily lives. Algorithms can easily be followed when completing any task. If you are putting something together, if the steps are completed in algorithm, it can easily be identified and corrected, you can continue from there. This helps to organize daily task or work related projects as well as provides you with problem solving tools if an issue arise.


He is looking for sequence of refinements -- the first being the broad outline.

For example, when writing code we might start with

public class X {
static void main(String args[]){

this class/program will compile and execute.

my next refinement might add:

public class X {
public void doInitialize(){
// 1. initialize variables
static void main(String args[]){

Expert:  lifesaver replied 8 years ago.
Thats too much of work.I will opt out and see if anybody else can help.

Expert:  Raj replied 8 years ago.
I can help you with this........
1. you need to know when can "while" be used best rather than "for" and same in reverse right??
2. difference between looping statement and is it conditional statement??
Expert:  Raj replied 8 years ago.
If you need answer to this then please specify
Yes in your post........Just after this