help ty
the question was" how many times does the while run for " my answer was that it runs one times because it says h = count converted to boolean which is one so its true so it starts running at the end it says h=!h so it becomes false and stops , the prof said it was wrong but im not sure why ? and hes very bad when being told hes wrong so if anyone can help me understand bc im confused it would be appreciated

12 Replies
I assume the answer is not "it doesn't run because the code does not compile"? Because
flag = count = 1
does not end in a semicolon and therefore it would not compile
So, the code is intentionally confusing but what you ask is right. The while loop runs once. The boolean is immediately switched at the only endpoint of this loop and h
is not modified another way. There's not a whole lot I can say other than that reallyGot it thank you i just wanted to make sure before I ask him to check my answers again
I wasn't sure myself so I actually rewrote it in dotnet fiddle https://dotnetfiddle.net/PAlaLF
Are you sure the question is not about the inner for-loop? That one can conditionally run multiple times.
Let me copy the question to show
Here is the translation to English:
1. (10points) What will be the output in the loop for the returned value 4.12? Please explain using a tracking table.
2. (10points) What will be the output in the loop for the returned value 3.33? Please explain using a tracking table.
3. ( points) How many times will the while loo5p run?
There's a few things that could manipulate the while loop to repeat:
-
h
is mutated in a way where it is false
, meaning h = !h
sets it to true
and repeats the loop.
- There is a continue
statement in the code that repeats the code.
- There is a jump to a label in the code to the start of the while loop.
None of these exist, so it's impossible.if this is homework, please note that we do not condone cheating.
nono I already solved it I’m just confused why my answer isn’t correct I already got graded on it
I see, good.
I am under the assumption that this was already submitted work and this is more a discussion as to what the reason is behind the answer they have gotten
Considering the fact that the teacher responded in saying it's wrong
Also, consider the fiddle I posted. The log is only written once and never more.
FusedQyou
I wasn't sure myself so I actually rewrote it in dotnet fiddle https://dotnetfiddle.net/PAlaLF
Quoted by
<@191282187016863744> from #help ty (click here)
React with ❌ to remove this embed.
So your logic is correct. Your thought process is exactly right. I don't see what else could be considered
Got it tysm