Could someone answer written response for the attached function please?
Describe a condition or error that would cause your iteration statement to not terminate and cause an infinite loop. If no such condition or error exists, explain how the loop could be modified to cause an infinite loop.
Is this for your understanding or a students? Technically you cannot give sample answers from their code to students until AFTER they submit their projects to the digital portfolio. You can use the AP examples though, I think!
It is for my understanding at this point. I am prepping for after the Create Task is submitted by students. I want to do practice Written Response questions using the student’s PPRs.
Note: I just switched variable names for the answers, everything else is the same!
AP’s released the following answer for this question as:
The loop iterates for each elements in allcities. An infinite loop is not possible since this for each loop iterates over all the elements of the list. A different loop structure would need to be used, such as a standard for or a while loop that would have a variable that wasn’t advancing toward the conditional.
I don’t really like their answer, so I would answer like this (PROBABLY WRONG):
The loop iterates over the allcities array. The loop condition is i < allcities.length, which means the loop will execute as long as the loop variable i is less than the length of the allcities array. Since the loop starts with i = 0, it will iterate through the array indices from 0 to allcities.length - 1,To intentionally create an infinite loop, you could modify the loop by removing or incorrectly updating the variable i within the loop body, ensuring that the condition i < allcities.length is always true. For instance, if you accidentally omit i++ or set i to a fixed value inside the loop body, it would result in an infinite loop.
I did put together a spreadsheet that covers the entire create task with answers to questions:
Annnnnnd, I made a video walking through the questions (No answers are given)