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

Why when I enter number 1, It does not break the loop. While r ~ = w_i % functio

ID: 3803005 • Letter: W

Question

Why when I enter number 1, It does not break the loop.

While r ~ = w_i % function will loop as long as condition is satisfied Q1 = input ('Enter number 1 's'); % requests the input of the player if Q1 = =1; %condition:if Q = 1 break % breaks the loop if condition is satisfied previously end end while r~ = w; % function will loop as long as condition is satisfied if Wrong_answer > 2; %Condition: if the total number of answers is greater than one.. Scoret = mytotalscore (correct2_answer, correct_answer, correct1_answer); disp ("you lose") %displays this message if the condition is satisfied return %function to stop the whole game if the condition is satisfied end choice1 = menu ('What was the first electronic computer called?", "Apple" "ENIAC", "ACORN Computer'); if choice1 ==a; correct_answer = = Correct_answers + 1; disp ("Your answer is correct'); % displays this message if the condition is satisfied break; %breaks the loop if condition is satisfied previously end

Explanation / Answer

Yes, this loop will always continue when it comes to the line 1 it never breaks because see the first three lines in the code

You have declared r=1 and w= 6 when the execution comes to the first line this variables r and w will always get initialised to 1 and 6 and when it enters the first while loop the condition always satisfies. So the loop will always continue without breaking.

To avoid this u must have to increment the r variable so that after some number of loops the while condition will be unsatisfied then the loop will get stop.

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote