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 


[Help] Started C# and trying to make unending Average Calc
Goto page Previous  1, 2, 3
 
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming
View previous topic :: View next topic  
Author Message
Estx
Expert Cheater
Reputation: 0

Joined: 04 Mar 2008
Posts: 172

PostPosted: Wed Jun 18, 2008 11:48 pm    Post subject: Reply with quote

samurai: Your code is slightly better, I've hardly had to use a generic list because I've always predetermined the size of my array (there-for rarely used Array.Resize()). Doesn't really matter that you missed out using decimals because I suppose you don't need pin-point precision for the example lol.

Did some performance tests though, no speed difference for 500 grades.
My example speed (ticks): 156250
Your example speed (ticks): 156250
Although the performance hit wont come in until much higher variables are stored, it becomes just coding preference and efficiency again. Even though I would say Lists are preferable compared to resizing arrays.

Lol anyway! From my point of view, both samuri25404 and HalfPrime have the same conclusion but aren't understanding each other. You're both right >.>

As for the topic starter, your answer is on the first page. Either of the last two posts. Although if you keep on reading you might learn a thing or two anyway. ;D
Back to top
View user's profile Send private message
DoomsDay
Grandmaster Cheater
Reputation: 0

Joined: 06 Jan 2007
Posts: 768
Location: %HomePath%

PostPosted: Thu Jun 19, 2008 7:55 am    Post subject: Reply with quote

Clarification:
A while loop is a modification of the do-while loop, which simply jumps to the check first. In this case, a while loop is is not a greate solution, nor is the do-while - the most efficient would be a couple of goto statements:
The do-while flow looks like this:
Code:
loopLabel:
<code>
if (<condition>) goto loopLabel

The while flow looks like this:
Code:
goto compareLabel
loopLabel:
<code>
compareLabel:
if (<condition>) goto loopLabel

samuri25404's while loop looks like this:
Code:
goto preCompareCodeLabel
loopLabel:
<code>
preCompareCodeLabel:
<get the input>
if (<condition>) goto loopLabel

But in this case, the code we want to produce should look like this:
Code:
loopLabel:
<get the input>
if (<input> == <stop>) goto outOfLoopLabel
<processing code>
goto loopLabel
outOfLoopLabel:

The actual difference, actually,is the fact that in samuri25404's code there are 2 unnececery goto's at it's flow's begining, which if removed, would look like my code(the one presented in C#).

EDIT:
a do{if (!<condition>){break;}}while(0); could also work, depends on the compiler.
Back to top
View user's profile Send private message
samuri25404
Grandmaster Cheater
Reputation: 7

Joined: 04 May 2007
Posts: 955
Location: Why do you care?

PostPosted: Thu Jun 19, 2008 3:43 pm    Post subject: Reply with quote

Both of the things that you posted are considered bad practice in the programming world (or at least, the C#/.NET world).

I posted an ideal, common solution.

_________________
Wiccaan wrote:

Oh jeez, watchout I'm a bias person! Locked.


Auto Assembly Tuts:
In Depth Tutorial on AA
Extended
Back to top
View user's profile Send private message
Display posts from previous:   
Post new topic   Reply to topic    Cheat Engine Forum Index -> General programming All times are GMT - 6 Hours
Goto page Previous  1, 2, 3
Page 3 of 3

 
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