Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6386609
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T03:02:53+00:00 2026-05-25T03:02:53+00:00

Whenever I think of using the while loop , I don’t see why I

  • 0

Whenever I think of using the while loop, I don’t see why I can’t just use an if statement instead. I know that a while loop runs ‘while’ a given statement is true, but if the condition is terminated inside the block instantaneously, then I cannot visualize anything happening ‘while’ something is true. If anyone can give me examples of how/why I should use a while loop. It would be very appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-25T03:02:53+00:00Added an answer on May 25, 2026 at 3:02 am

    I’m going to try to give you a very high-level answer because I think it will be easier to grasp intuitively.

    Think of all algorithms as recipes. A typical recipe might have parts that look like the following:

    • If the peanut has a shell, separate it from the shell
    • Beat an egg until it is whipped and bubbly
    • Take 5 onions and chop each of them in half

    These types of directions have you do tasks in different ways.

    The first one is really an “if” statement. You do something if a condition (peanut has a shell) is true. You literally do:

    if (not shelled) {
      shell the peanut! // happens once
    }
    

    The second one is a while loop. You beat the egg while it is not whipped and bubbly. You do the same thing over and over (whipping) continuously, and you look at it (over and over) when doing this to check and see if it has turned very bubbly. Once it gets bubbly and whipped enough, you stop. When you stop it is because you have passed your “While” condition. An important thing to note is that before you start, you don’t necessarily know just how many “beats” of an egg it takes to get it whipped. You just have to do it many times and check (with your eyes) many times. You literally do:

    while(not whipped enough) {
      beat egg! // happens over and over
    }
    

    Just like in recipes, you don’t want someone doing a certain action until the end of time, so you must always make sure your while loops have sensible stopping conditions. Most while loops depend on something changing inside of the loop and will stop when that thing has changed enough.


    The third recipe example is a for loop. For each onion you have (5) you do something once to that one onion. You literally do:

    for (onions 1 to 5) {
      Chop an onion! // done 5 times total, once per onion
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I've been using for a while a small git repository that has been set-up
As long as I can remember, whenever I use a module I include a
How can I have a WinForms program do some specific thing whenever a certain
Whenever I use the signal/slot editor dialog box, I have to choose from the
I'm trying to make sure that I don't leave any loose ends open in
While I do know the above goal is rather challenging to achieve, I know
I am working on a project that is using NetTcp bindings for talking to
I have been using LINQ to SQL for a while, and there is one
I'm trying to use a NSProgressIndicator (indeterminate) inside of a statusbar-menu. I'm using an
At my job they use a central login facility on internal webpages. Whenever an

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.