![]() My suggestion when doing something like this is to write down on a paper what each value increments to at each iteration to help you understand how the loop works. ![]() This allows the first loop to also reach 9 and be able to go into the second loop each time. ![]() In the second answer the difference is that num_second gets reset back to 1 each time it completes that second loop. Then, num_front will increment by 1 go through the first loop again but then it won't go to the second loop because num_second is already at 9 so it will just keep incrementing num_front until it reaches 9 then the whole program will stop. So, as you are going through the first while loop it makes the first check that num_front is <=9 and in this case it is, so it goes to the second while loop and increments by one until it reaches 9 and that loop stops. In the first solution you gave, you made num_second a local variable and this makes it so it only resets to 1 that very first time. ![]() You are not updating num_second in the correct spot. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |