When the program is run, it never ends and acts like it is stuck in an infinite loop. Help this colleague figure out what is wrong with the program. a. Explain what is happening in the program b. Come up with a mechanism which shows that this program is indeed in an infinite loop. c. Come up with a solution which fixes this problem.
Types of Loop
Loops are the elements of programming in which a part of code is repeated a particular number of times. Loop executes the series of statements many times till the conditional statement becomes false.
Loops
Any task which is repeated more than one time is called a loop. Basically, loops can be divided into three types as while, do-while and for loop. There are so many programming languages like C, C++, JAVA, PYTHON, and many more where looping statements can be used for repetitive execution.
While Loop
Loop is a feature in the programming language. It helps us to execute a set of instructions regularly. The block of code executes until some conditions provided within that Loop are true.
A colleague decided that the PrintInt subprogram should print a new line after the integer has been printed, and has modified the PrintInt to print a new line character as follows.
A colleague felt that the PrintInt subprogram should print a new line after the number, so he updated the PrintInt to output the following new line character.
# subprogram: PrintInt
# author: Charles W. Kann
# purpose: To print a string to the console
# input: $a0 - The address of the string to print.
# $a1 - The value of the int to print
# returns: None
# side effects: The String is printed followed by the integer
value.
.text
PrintInt:
# Print string. The string address is already in $a0
li $v0, 4
syscall
# Print integer. The integer value is in $a1, and must
# be first moved to $a0.
move $a0, $a1
li $v0, 1
syscall
# Print a new line character
jal PrintNewLine
#return
jr $ra
When the programme is executed, it never stops and appears to be stuck in an unending loop. Assist this colleague in determining what is wrong with the programme.
A) Describe what is happening in the programme; B) devise a method that would demonstrate that the programme is, in fact, in an infinite loop.
c. Develop a solution that resolves this issue.
When the
a. Explain what is happening in the program
b. Come up with a
c. Come up with a solution which fixes this problem.
Trending now
This is a popular solution!
Step by step
Solved in 4 steps