Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Dark GDK / For / While

Author
Message
Marsh0
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 27th Feb 2010 17:26
So i have basically just been hammering away at c++ not really reading any books or tutorials.

What is the difference between a for and a while?

Your signature has been erased by a mod - Please reduce it to 600x120 maximum size
Benjamin
21
Years of Service
User Offline
Joined: 24th Nov 2002
Location: France
Posted: 27th Feb 2010 17:29
kklouzal
15
Years of Service
User Offline
Joined: 15th May 2009
Location: Arizona
Posted: 27th Feb 2010 17:30
It's just the method of execution (as far as i know)

for (int i = 0; i < 10; i++)
{
//code
}

int i = 0;
while (i < 10)
{
//code
i++
}

same thing, different code.

Add me to your MSN!
Marsh0
15
Years of Service
User Offline
Joined: 18th Mar 2009
Location:
Posted: 27th Feb 2010 18:33
Ah, thanks kklouzal. I prefer while statements for some reason . Prob just what i started with.

Your signature has been erased by a mod - Please reduce it to 600x120 maximum size
Cuddle Bunniezzz 12
15
Years of Service
User Offline
Joined: 14th Jan 2009
Location: Buffalo, NY
Posted: 27th Feb 2010 19:06 Edited at: 27th Feb 2010 19:07
Well, a while loop keeps on going until a condition is false ex:


And a For Loop keeps on going until a condition is meet (in the example, it is while variable "i" is less than "10".



You can also see that For loops can be used to cycle through arrays, while loops can do this too, but it's a bit more logical for a for loop to do that.

http://www.darkgdk.us/ <- You can now submit pages, upload images, yet were lacking content. We need your help!
Mireben
16
Years of Service
User Offline
Joined: 5th Aug 2008
Location:
Posted: 27th Feb 2010 23:01
For loops are used when you know in advance how many times you want the loop to be executed. An example is going through a fixed-size array. The while loop is used when you don't know how many times the loop will be executed, you only know that it should keep running as long as the condition is met.

Login to post a reply

Server time is: 2024-11-19 15:24:04
Your offset time is: 2024-11-19 15:24:04