(Solved) : 3 Thinking Loops 3 Points Think Loops 122 Always Concentrate Single Iteration Loop Loop Al Q44028287 . . .
3 Thinking about Loops (3 points) When we think about loops in 122, we will always concentrate on a single iteration of the loop. A loop will almost always modify something; the following loop modifies the local assignable i while (i <n) { i-i + 4; In order to reason about the loop, we have to think about the two different values stored in the local assignable i. We use the variable i to talk about the value stored in the local i before the loop runs (before the loop guard is checked for the first time). We use the “primed variable i’ to talk about the value stored in the local i after the loop runs exactly one time before the loop guard is next checked). 4.1 Consider the following loop: while (i <n) { kuj + k; j-j.2 + i; i . i + 1; . If i=7, j = 3, and k = 9, then assuming 7<n, – Dj Dand k =D • If i=2y, j =r-y, and k = y, then assuming 2y <n, in terms of r and y, 1 – L and K = • Ifj=k, then assuming i <n, in terms of i and k, and R = • In general, assuming i <n, then in terms of i, j, and k, and K = Note that we always say “assuming (something) <n,” because if that were not the case the loop wouldn’t run, and it wouldn’t make any sense to be talking about the values of the primed variables. 4.2 Consider this loop while (…) i-i + 3; j-j.2 + i; k = k + 1 – 1: Be careful, it looks similar but is trickier! Give simplified answers. . If i=7, j =3, and k = 9, then assuming the loop guard evaluates to true, . In general, assuming the loop guard evaluates to true, then in terms of i, j, and k. and k = 4.3 Consider this loop: while (a > &6 b > 0) { if (a > b) { a a.b; } else { b = b-a; • If a 94 and b 12, then d’ and . If a = 1 + y and b= I, where I and y are both positive integers, then and . If a a nd b + 2, where is a positive integer and is a non-negative integer, then and V • Ifa > O and b>0, one of the two cases above will always be the case. Therefore, we can conclude which of the following about the values stored in a and b after an arbitrary iteration of the loop? (Check all that apply) d’>0 and > 0 d’>0 and V > 0 d’>0 and > 0 d’>0 and > 0 Show transcribed image text 3 Thinking about Loops (3 points) When we think about loops in 122, we will always concentrate on a single iteration of the loop. A loop will almost always modify something; the following loop modifies the local assignable i while (i 0 d’>0 and V > 0 d’>0 and > 0 d’>0 and > 0
Expert Answer
Answer to 3 Thinking about Loops (3 points) When we think about loops in 122, we will always concentrate on a single iteration of …
OR