Given the following pseudocode:
Which of the following is the output of the code?
Given the following pseudocode:
Which of the following is the output of the code?
The pseudocode starts by setting the variable @count to 1. A loop then increments @count by 1 as long as @count is less than 10. When @count reaches 9, the loop executes one last time, increments it to 10, and then exits the loop because the condition @count < 10 is no longer true. Thus, the final value of @count is 10, making the output of the code 10.
Shouldn't this be ten? It says as Long as @count is LESS THAN 10, add 1. So when @count is equal to 10, It should stop. Because 10 is EQUAL TO 10. 10 is NOT LESS THAN 10
The loop is exited when count is 10
It's suppose to be 10. It enters loop for the final time at 9. Which sets it to 10. It can't run the loop after that since 10 is not less than 10. So it returns 10.
C. 10 for count =9: count < 10 count = 9+1 = 10 for count =10: loop does not enter count value ends with 10
yes, it should be 10.
I agree, it should be 10
The answer is C. It would not print out 11 because the condition is LESS THAN not LESS THAN EQUAL TO
C is the correct answer, the code only loops if @count is under 10, once its value is 10, it stops looping, meaning the final output is 10. or C
Consider the following simple loop (python): count = 1 while count < 10: count += 1 print (count) that will print 10 in the console!
@count=1. @count <10 @count= @count(1) + 10 So.. @count = 11
Sorry, third line is.. @count= @count(10)+1 Since it is set @count =1 for @count < 10
I believe it is 11 because when we look at the pseudo code, it has the +1 after the <10. This means that one more numbers adds up to the current one, therefore, it comes out as 10.
The plus one might be after the check, but the loop checks that the variable is less than ten, not less-than-or-equal-to ten. so once the variable reaches nine, it would be nine plus one, equaling ten, and then its checked again, and then leave the loop.