Friday, July 31, 2009

In C Programming, can you have a do while loop within another one?

are brackets closed as soon as they reach the next closing one or can you 'skip' a closing one so to speak?

In C Programming, can you have a do while loop within another one?
Sure you can. You can have as many loops as you like.





Nope, you cannot 'skip' a closing bracket. The compiler will complain - it won't be able to figure out what needs to be done. All your brackets must match and the closing one is matched with the immediately previous opening one.


So, you cannot have a scenario like the one below:





{ // Opening bracket 1





{ // Opening bracket 2





} // Closing bracket 1





} // Closing bracket 2





In any case, the system would interpret "Closing bracket 1" as "Closing bracket 2".
Reply:You can loops within loops, and if's within if's etc





while (someCondition)


{


do everything in the braces


while( some other Condition)


{


do everything in THESE braces


make sure condition to stop loop is here


}//inner while


make sure condition to stop loop is here


}//end outter loop
Reply:it is for loop ,maam its execution is also the same naaa
Reply:Braces close in the reverse order to which they open.





while (someCondition) {


do_something();


while (someOtherCondition) {


do_something_else();


}


do_another_thing();


}
Reply:Of course.

silk flowers

No comments:

Post a Comment