Cheat Engine Forum Index Cheat Engine
The Official Site of Cheat Engine
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


[C++] Explain to me

 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Fri Aug 24, 2007 11:16 am    Post subject: [C++] Explain to me Reply with quote

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
View user's profile Send private message
UnLmtD
Grandmaster Cheater
Reputation: 0

Joined: 13 Mar 2007
Posts: 894
Location: Canada

PostPosted: Fri Aug 24, 2007 11:23 am    Post subject: Reply with quote

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
View user's profile Send private message
zart
Master Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 351
Location: russia

PostPosted: Fri Aug 24, 2007 11:24 am    Post subject: Re: [C++] Explain to me Reply with quote

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
View user's profile Send private message
Heartless
I post too much
Reputation: 0

Joined: 03 Dec 2006
Posts: 2436

PostPosted: Fri Aug 24, 2007 11:29 am    Post subject: Reply with quote

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
View user's profile Send private message
UnLmtD
Grandmaster Cheater
Reputation: 0

Joined: 13 Mar 2007
Posts: 894
Location: Canada

PostPosted: Fri Aug 24, 2007 11:30 am    Post subject: Reply with quote

You need it.
_________________
Back to top
View user's profile Send private message
DemonDays!
Advanced Cheater
Reputation: 0

Joined: 16 Dec 2006
Posts: 58

PostPosted: Fri Aug 24, 2007 11:37 am    Post subject: Reply with quote

always declare it out of the loop check. Smile
Back to top
View user's profile Send private message
zart
Master Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 351
Location: russia

PostPosted: Fri Aug 24, 2007 11:46 am    Post subject: Reply with quote

UnLmtD wrote:
You need it.


No you don't. You can compile a for loop to be infinite, the following does work:

for(;Wink

@aznboy

You don't NEED it, but it's a good place to initialize or reset your incrementing value

_________________
0x7A 0x61 0x72 0x74

TEAM RESURRECTiON
Back to top
View user's profile Send private message
UnLmtD
Grandmaster Cheater
Reputation: 0

Joined: 13 Mar 2007
Posts: 894
Location: Canada

PostPosted: Fri Aug 24, 2007 11:52 am    Post subject: Reply with quote

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
View user's profile Send private message
zart
Master Cheater
Reputation: 0

Joined: 20 Aug 2007
Posts: 351
Location: russia

PostPosted: Fri Aug 24, 2007 11:54 am    Post subject: Reply with quote

UnLmtD wrote:
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.


he's asking WHAT the statement means.

this is a completely valid for loop:

for(; count < 10; count++)

As long as count has already been initialized. Well technically it will work even if it hasn't been - but it will just grab random memory and the output won't be nice Wink

_________________
0x7A 0x61 0x72 0x74

TEAM RESURRECTiON
Back to top
View user's profile Send private message
lurc
Grandmaster Cheater Supreme
Reputation: 2

Joined: 13 Nov 2006
Posts: 1900

PostPosted: Fri Aug 24, 2007 12:37 pm    Post subject: Re: [C++] Explain to me Reply with quote

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
View user's profile Send private message
Robotex
Master Cheater
Reputation: 0

Joined: 05 Sep 2006
Posts: 378
Location: The pizza country!

PostPosted: Fri Aug 24, 2007 7:56 pm    Post subject: Reply with quote

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
View user's profile Send private message
Noz3001
I'm a spammer
Reputation: 26

Joined: 29 May 2006
Posts: 6220
Location: /dev/null

PostPosted: Sat Aug 25, 2007 3:13 am    Post subject: Reply with quote

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
View user's profile Send private message MSN Messenger
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB © 2001, 2005 phpBB Group

CE Wiki   IRC (#CEF)   Twitter
Third party websites