Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

(b) Next consider the following code snippet unsigned long next iteration_time 0

ID: 3871613 • Letter: #

Question

(b) Next consider the following code snippet unsigned long next iteration_time 0; void loop() current-time = millis(); if (current_time do_some_computation(); //this code is written by someone else Serial.println(current_time); next_iteration_time-next_iteration_time 100; next iter ation_time)// iteration Making all the same assumptions as above, again fill in the table below for what is printed the second through fifth times the print statement is called. Which iteration Value printed by Serial.println() 0 3 4

Explanation / Answer

In the given program we are printing current_time ,

so in the first itration we can see that the value of current_time is 0.

And then we are incrementing next_iteration_time by a value of 100.

So the value printed by statement Serial.println(current_time) is current_time not iteration time.

So in the loop current_time will be based on milli() function.

So whatever value we are getting from milli() function that will be printed out.

Suppose doing the computation of each iteration we consume 50 time units .

So output or the value of current_time will be increasing by 50 in each iteration as

which iteration Value printed by Serial.println()

1 0

2 50

3 100

4 150

5 200

Here we are not incrementing current_time but we can't stop current_time to move .

So time will be increasing continuously .

Here we have taken assumption of 50 time units for one iteration's time consumption , but exactly it will be the value returned by milli() function.