View previous topic :: View next topic |
Author |
Message |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Fri Aug 24, 2007 11:16 am Post subject: [C++] Explain to me |
|
|
I'm not sure what my book is trying to tell me so I'll ask you guys.
for(int = 0; count < 10; count++)
The red part is checking when to start, right?
The blue part is checking when to stop?
The yellow part is telling it what to do?
I'm confuse, please explain this to me.
_________________
What dosen't kill you, usually does the second time. |
|
Back to top |
|
 |
UnLmtD Grandmaster Cheater
Reputation: 0
Joined: 13 Mar 2007 Posts: 894 Location: Canada
|
Posted: Fri Aug 24, 2007 11:23 am Post subject: |
|
|
This is how I do it, it increases x by one every loop.
Code: | for ( int x = 0; x < 10; x++ ) {} |
_________________
Last edited by UnLmtD on Fri Aug 24, 2007 11:25 am; edited 1 time in total |
|
Back to top |
|
 |
zart Master Cheater
Reputation: 0
Joined: 20 Aug 2007 Posts: 351 Location: russia
|
Posted: Fri Aug 24, 2007 11:24 am Post subject: Re: [C++] Explain to me |
|
|
HornyAZNBoy wrote: | I'm not sure what my book is trying to tell me so I'll ask you guys.
for(int = 0; count < 10; count++)
The red part is checking when to start, right?
The blue part is checking when to stop?
The yellow part is telling it what to do?
I'm confuse, please explain this to me. |
Sort of correct... The first part of the statement is used to initialize things, it is not nessecary though - normally this is where you set the variable your using. The second part is the condition, so yes "for how long". The last part is what your telling it to do every iteration
_________________
0x7A 0x61 0x72 0x74
TEAM RESURRECTiON |
|
Back to top |
|
 |
Heartless I post too much
Reputation: 0
Joined: 03 Dec 2006 Posts: 2436
|
Posted: Fri Aug 24, 2007 11:29 am Post subject: |
|
|
So what your saying is that you don't always need the part in red.
_________________
What dosen't kill you, usually does the second time. |
|
Back to top |
|
 |
UnLmtD Grandmaster Cheater
Reputation: 0
Joined: 13 Mar 2007 Posts: 894 Location: Canada
|
Posted: Fri Aug 24, 2007 11:30 am Post subject: |
|
|
You need it.
_________________
|
|
Back to top |
|
 |
DemonDays! Advanced Cheater
Reputation: 0
Joined: 16 Dec 2006 Posts: 58
|
Posted: Fri Aug 24, 2007 11:37 am Post subject: |
|
|
always declare it out of the loop check.
|
|
Back to top |
|
 |
zart Master Cheater
Reputation: 0
Joined: 20 Aug 2007 Posts: 351 Location: russia
|
|
Back to top |
|
 |
UnLmtD Grandmaster Cheater
Reputation: 0
Joined: 13 Mar 2007 Posts: 894 Location: Canada
|
Posted: Fri Aug 24, 2007 11:52 am Post subject: |
|
|
Yes for an infinite loop, but I don't see him do for(count < 10; count++) And I beleive that's what he was asking for.
_________________
|
|
Back to top |
|
 |
zart Master Cheater
Reputation: 0
Joined: 20 Aug 2007 Posts: 351 Location: russia
|
|
Back to top |
|
 |
lurc Grandmaster Cheater Supreme
Reputation: 2
Joined: 13 Nov 2006 Posts: 1900
|
Posted: Fri Aug 24, 2007 12:37 pm Post subject: Re: [C++] Explain to me |
|
|
HornyAZNBoy wrote: | I'm not sure what my book is trying to tell me so I'll ask you guys.
for(int = 0; count < 10; count++)
The red part is checking when to start, right?
The blue part is checking when to stop?
The yellow part is telling it what to do?
I'm confuse, please explain this to me. |
Code: |
for(
int count = 0; //Start Loop at 0
count < 10; // Loop for as long as count is lower then 10
count++ // increment by 1
)
{
cout << "hi" << endl;
} |
Output:
hi
hi
hi
hi
hi
hi
hi
hi
hi
So this will basically say hi until the loop is over 10.
_________________
|
|
Back to top |
|
 |
Robotex Master Cheater
Reputation: 0
Joined: 05 Sep 2006 Posts: 378 Location: The pizza country!
|
Posted: Fri Aug 24, 2007 7:56 pm Post subject: |
|
|
you can make it also
for(;;Sleep(100))
{
<code here>
}
usefull for making loops in threads
_________________
ASM/C++ Coder
Project Speranza lead developer |
|
Back to top |
|
 |
Noz3001 I'm a spammer
Reputation: 26
Joined: 29 May 2006 Posts: 6220 Location: /dev/null
|
Posted: Sat Aug 25, 2007 3:13 am Post subject: |
|
|
I usually use the last param just to keep track of how many times it has looped.
Code: | if (x == 10) break; |
|
|
Back to top |
|
 |
|