Wrox Programmer Forums
Go Back   Wrox Programmer Forums > C# and C > C# 1.0 > C#
|
C# Programming questions specific to the Microsoft C# language. See also the forum Beginning Visual C# to discuss that specific Wrox book and code.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the C# section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 26th, 2010, 02:50 PM
Authorized User
 
Join Date: Nov 2010
Posts: 13
Thanks: 4
Thanked 0 Times in 0 Posts
Post difference between for and while loop?

Hi,
What is the difference between for and while loop?
which one is better to use in which condition?

Thanks
 
Old December 28th, 2010, 11:40 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Hi there,

You may find this useful: http://www.lmgtfy.com/?q=difference+...hile+loop+C%23

Cheers,

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
The Following User Says Thank You to Imar For This Useful Post:
smfarooq (January 23rd, 2011)
 
Old January 23rd, 2011, 12:14 PM
Authorized User
 
Join Date: Nov 2010
Posts: 13
Thanks: 4
Thanked 0 Times in 0 Posts
Post While VS For Loop

Hi

Sir,

While loop is better or for loop is better, Performance wise. ?

Thanks.
 
Old January 23rd, 2011, 12:27 PM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

It's not about performance; it's about serving different needs....

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!
 
Old January 24th, 2011, 11:23 AM
Authorized User
 
Join Date: Nov 2010
Posts: 13
Thanks: 4
Thanked 0 Times in 0 Posts
Post While VS For Loop

Hi,

Sir, if "while loop" is fulfilling our needs, then why there is another "for loop" and why "for loop" isn't obsolete yet?

Thanks..
 
Old January 24th, 2011, 11:33 AM
Imar's Avatar
Wrox Author
 
Join Date: Jun 2003
Posts: 17,089
Thanks: 80
Thanked 1,576 Times in 1,552 Posts
Default

Did you read the first few articles from the Google link I posted earlier? You'll find explanations such as:
Quote:
A while loop is very much similar to a for loop except that initialization, checking the boolean condition and incrementing the counter value is done at different steps as shown in the below example, otherwise while loop is same as the for loop.
In other words, each loop serves a different need.

Imar
__________________
Imar Spaanjaars
http://Imar.Spaanjaars.Com
Follow me on Twitter

Author of Beginning ASP.NET 4.5 : in C# and VB, Beginning ASP.NET Web Pages with WebMatrix
and Beginning ASP.NET 4 : in C# and VB.
Did this post help you? Click the button below this post to show your appreciation!





Similar Threads
Thread Thread Starter Forum Replies Last Post
Loop twice, then inside loop select nodes?? JohnBampton XSLT 2 March 9th, 2009 05:21 AM
Is there a difference? ironchef Java Basics 2 October 6th, 2006 03:26 AM
what is the difference? chuck_schuldiner Javascript How-To 2 February 10th, 2005 01:46 AM
what is the difference between... chuck_schuldiner Javascript 2 February 10th, 2005 01:41 AM
nested while loop doesn't loop hosefo81 PHP Databases 5 November 12th, 2003 08:46 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.