Programming C, C++, Java, PHP, Ruby, Turing, VB
Computer Science Canada 
Programming C, C++, Java, PHP, Ruby, Turing, VB  

Username:   Password: 
 RegisterRegister   
 Procedure
Index -> Programming, Turing -> Turing Help
View previous topic Printable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic
Author Message
mike200015




PostPosted: Sun Feb 27, 2005 11:39 am   Post subject: Procedure

in a program im making, i have 2 procedures that have code which are very similar, except for about 10 lines, in a few different spots, so is there a way to make a procedure for the stuff that are similar, and then i can just add in the lines that are different?
Sponsor
Sponsor
Sponsor
sponsor
Cervantes




PostPosted: Sun Feb 27, 2005 11:44 am   Post subject: (No subject)

Pass parameters into your procedure.
If the lines that are different are just different because they use different variables, you can pass the variable into the procedure.
If the lines that are different really are different, you can wrap them inside an if statement and use a boolean parameter to determine whether to go inside that if statement or not.
mike200015




PostPosted: Sun Feb 27, 2005 11:52 am   Post subject: (No subject)

yea the lines are like totally different .. not just like a different colour or sumtin.. but its not like 1 big chunk in the middle thats different, i have like 5 lines in 1 spot.. and like 3 lines in another etc.
Cervantes




PostPosted: Sun Feb 27, 2005 12:05 pm   Post subject: (No subject)

Then it's up to you to decide whether you should wrap those lines in if statements (using a boolean parameter) or make a whole new procedure. Personally, I wouldn't decide on number of lines of each method, I would make my decision based on what I'm trying to do with either procedure. If the purpose is the same or very similar, I'd go with the boolean method.
Also, look for ways that you can clump those different lines together, so as to use less if statements.
mike200015




PostPosted: Sun Feb 27, 2005 12:09 pm   Post subject: (No subject)

Smile kk... thnx for ur help Exclamation
person




PostPosted: Sun Feb 27, 2005 6:05 pm   Post subject: (No subject)

im not so sure that this is gonna help u but cant u just make wats same a procedure?
jamonathin




PostPosted: Sun Feb 27, 2005 6:18 pm   Post subject: (No subject)

not necessarily, because if what's different is inside a for loop for example, and he's usin' the for loops for his array's, then he cant put everything else in a proc.
ssr




PostPosted: Sun Feb 27, 2005 7:08 pm   Post subject: (No subject)

I donno
may be u can make numerous procs depending on the different codes
and make a large proc which include ifs, and put down teh small procs
8)
may be
just may be....
Sponsor
Sponsor
Sponsor
sponsor
Display posts from previous:   
   Index -> Programming, Turing -> Turing Help
View previous topic Tell A FriendPrintable versionDownload TopicSubscribe to this topicPrivate MessagesRefresh page View next topic

Page 1 of 1  [ 8 Posts ]
Jump to:   


Style:  
Search: