| View previous topic :: View next topic |
| Author |
Message |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Mon Jan 28, 2008 10:23 pm Post subject: |
|
|
Ok, I'll go ahead and exaplain the for loop.
First of all, this is the format:
1: An assignment that occurs once, right at the beginning of the loop.
2: A loop condition, loop until this happens. Its like this:
3: A statement to occur once after each loop through.
~~
Let's go through an example:
| Code: |
for (int i = 0; i < 10; i++)
{
cout << "Hi!\n";
}
|
This prints out "Hi!" 10 times to the screen.
~~~
Let's analyze it:
1:
int i = 0;
This will happen once, right at the beginning. Note that it is an initialization. Remember that it doesn't have to be one, but it usually is.
2:
i < 10
Loop until this happens, it would be like
3:
i++
This is an assignment statement to go on after each loop through.
~~
Note that if you don't want to do something, just put the semicolon there. An infinite loop that does nothing would be:
~~
Let's go back and analyze that previous loop:
[code]
for (; MyLoop(); Sleep(10))
{}
[code]
1: Nothing here. We don't need to do anything here, so just leave it blank.
2:
MyLoop()
Loop until MyLoop() returns true.
3:
Sleep(10)
An assignment statement. It just makes the computer wait for 10 ms, so it has a little bit of time to catch its breath, and you usually don't notice it most of the time; the computer's incredibly fast.
~~
That's not so hard, right?
_________________
|
|
| Back to top |
|
 |
guernica Grandmaster Cheater Supreme
Reputation: 0
Joined: 20 Jun 2007 Posts: 1211
|
Posted: Mon Jan 28, 2008 10:30 pm Post subject: |
|
|
i understand now, but what benefit would it be to use that instead of while? just never mind me, ill accept the knowledge and apply it later. in this situation, ill use while.
_________________
| georgezilka wrote: | | im looking for experience (EXP) hacks for maple story are there any where it can give instant level up ? |
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
|
| Back to top |
|
 |
samuri25404 Grandmaster Cheater
Reputation: 7
Joined: 04 May 2007 Posts: 955 Location: Why do you care?
|
Posted: Tue Jan 29, 2008 3:19 pm Post subject: |
|
|
| Wiccaan wrote: |
| Code: | for( ; ; )
{
if( bWantsExit )
break;
} |
|
What happened to your advertising "Sleep(10)" everywhere?
| Code: |
for (;;)
{
if (bWantsExit) break;
Sleep(10);
}
|
:p
Btw, grats on 1500 posts.
_________________
|
|
| Back to top |
|
 |
atom0s Moderator
Reputation: 205
Joined: 25 Jan 2006 Posts: 8588 Location: 127.0.0.1
|
|
| Back to top |
|
 |
|