Sunday, August 2, 2009

Programming?

We decided to add a counter to the loop to count the records. What is the appropriate syntax to maintain


a counter?


A. ADD 1 TO count


B. ADD count to 1


C. MOVE 1 to count


OR


D. ADD 1 to count GIVING new_count

Programming?
whenever you not sure about how many times you want your loopto iterate use while loop later do*





i agree with above post but can be done also as





count=0;


while(record!=empty)


{


//your code(bussiness logic)


count++


}do





well i think B n C are more relavant..yet feel its not whether you do postincrement or preincrement..its use of correct loop


syntax.WHILE LOOP SUITS YOU THE MOST.





hope this will help


Cheers:)
Reply:You need to be a little clearer. Evry lang is a bit diff.





IN VB





dim counter as int32=1 (adjust int32 for size)





Start loop





counter+=1 (this come last in your statement)





End loop
Reply:A loop condition is a test that determines whether the statements within the body of the loop will be executed at least once. If they are exectuted then, the condition also determines whether they will be executed once again.





The process is regulated by a loop control variable (counter). Upon each iteration, the inner statements are executed—and the loop control variable is incremented or decremented.





There are various types of loops, i.e., Do Until, Do While, and For Loops. The loop control condition can be located at either the top or the bottom of the loop. If it is located at the bottom, the body of the loop is guaranteed to be processed at least once.





Below are three examples of loops. The loop control variable is the "count" variable.





1)


FOR count = 0, count %26lt; 6, ++count


Statement_1;


Statement_2


NEXT





2) The statements within the next loop will never exectute.





count = 7;





DO WHILE (count %26lt; 6)


{


Statement_1;


Statement_2;


++count


}





3) This loop will execute the inner statements once only.





count = 1





Do


{


Statement_1;


Statement_2;


-- count


} WHILE (count %26gt; 0)
Reply:What programming language are you using? In C, what you are asking would look something like this:





count = 0;


while(...) {


do_something().....


count = count + 1;


}


No comments:

Post a Comment