Jump to content

Re:Differenece between for and while loop

- - - - -

  • Please log in to reply
3 replies to this topic

#1
ahshan

ahshan

    Newbie

  • Members
  • Pip
  • 8 posts
Hello to everyone,

I am bit confused on the difference between for(determinate loop) and while loop(indeterminate loop)

what makes it different,as we convert for loop to while loop and vice-versa.

please give a example to clarify it.


Thank you

#2
untitled_1

untitled_1

    Learning Programmer

  • Members
  • PipPipPip
  • 89 posts
the main difference is that you can convert any for loop into while but you cant always convert a while loop to a for or its not really worth doing that, that's what i think at least.

#3
WingedPanther

WingedPanther

    A spammer's worst nightmare

  • Moderators
  • 16,831 posts
  • Location:Upstate, South Carolina
  • Programming Language:C, C++, PL/SQL, Delphi/Object Pascal, Pascal, Transact-SQL, Others
  • Learning:Java, C#, PHP, JavaScript, Lisp, Fortran, Haskell, Others
Except, in C++ you can, because there is nothing that says a for loop has to be a simple increment.
Programming is a branch of mathematics.
My CodeCall Blog | My Personal Blog

#4
dargueta

dargueta

    Writes binary right handed and hex left handed

  • Moderators
  • 4,717 posts
  • Programming Language:C, Java, C++, PHP, Python, Perl, Assembly, Bash, Others
  • Learning:JavaScript
While loops are used when you're doing an unknown number of iterations and are instead waiting on some condition. For loops are used when you have a known number of iterations you need to do.
sudo rm -rf /




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users