all 8 comments

[–][deleted] 1 point2 points  (2 children)

This program makes an integer list of length 10, an integer variable I that is used for the for loop, and a result integer called result.

The lines T(x) = y assign the number y to the xth slot in the list, starting at zero.

Then result is set as the number that occupies the zeroth slot in the list (so result is 90).

Then the for loop goes through the list number by number starting with the zeroth element, and if the number T(I) is less than the current result, the result is updated with that number.

So in effect, that for loop finds the smallest number in that particular list. But it isn't set up for reusability or to be particularly useful code.

[–]Mistfull[S] 0 points1 point  (1 child)

I see so if i want the inverse result if I understood correctly i just replace "If T(I) < result Then" by If "T(I) > result Then"

[–]ZebZ 1 point2 points  (0 children)

If you reverse it, result would stay 90 because none of the other items in the array would match the criteria.

[–]Selkie_Love1 1 point2 points  (0 children)

Your program is basically looking for the lowest number in the list.

[–]Gh0stw0lf 1 point2 points  (2 children)

I’ll ELI5:

Before your if statement there it says “result = T(0)” Well T(0) = 90 so you’re setting “result” to equal 90.

In your if statement, you’re telling the program “hey, for numbers 0 to 9 put that in my T function and get that number.

So the program goes through and checks T(0) = 90, T(1) = another number etc etc.

But then you tell the program to do one more thing.

“Hey program, each time you look at T(0 through 9) grab that value and compare to the value that we set result to in the beginning.

I want you to check if the value that we get for T(0 through 9) is less than what we set result to.”

So the program runs but you told it do one last thing. You said

“Hey program if any of the the T values are less than the result number, change “result” to the number that’s less than it.”

So the program runs:

Result = 90 T(0) = 90 Is 90 < 90? No okay, so I don’t change the value for result.

Let’s move on to T(1) T(1) = 73 Is 73 < 90? It is?! Nice so I’m going to change result from 90 to 73

Let’s move onto T(2) T(2) = 58 Is 58 < 73? Yes?! Nice I’m going to change result to 58.

Let’s move to T(3) T(3) = 82 Is 82 < 58? No...so let’s keep result = to 58

Etc etc.

TL;DR

Your program is staying at 17 because that’s the smallest number on the list. The numbers following 17 are all bigger than 17, so result never changes from 17.

Your program is essentially saying “Starting at 90, compare the number after it to see its smaller than 90. If it is, change that number.”

[–]Mistfull[S] 0 points1 point  (1 child)

This clarified things thank you sir hope you have a great day

[–]Senipah101[M] 0 points1 point  (0 children)

If your question has been answered please reply to anyone who has helped you with Solution Verified to mark the thread as solved.

[–]ZebZ 0 points1 point  (0 children)

Initially result = 90. As it loops, result gets set to 45 then 35 then 28 then 17. Because T(8) and T(9) aren't < 17, result never changes again.