VHDL Questions and Answers – LOOP Statement – 1

This set of VHDL Multiple Choice Questions & Answers (MCQs) focuses on “LOOP Statement – 1”.

1. A loop statement is used where we needs to ________
a) Select one from many choices
b) Check a condition
c) Repeat the statements
d) Choose one from two cases
View Answer

Answer: c
Explanation: As the name suggests, a loop statement includes a sequence of statements which have to be executed repeatedly zero or more times. There are different iteration schemes available to generate loops in which some condition may be included to generate a finite loop.

2. Loop is a ________ statement.
a) Concurrent
b) Sequential
c) Assignment
d) Functional
View Answer

Answer: b
Explanation: Like IF, WAIT, CASE, LOOP is also intended exclusively for sequential code. It is a sequential statement which can be used inside a process, function or procedure only.

3. How many styles of loop statement does the VHDL have?
a) 2
b) 3
c) 4
d) 5
View Answer

Answer: a
Explanation: There are two different styles of the loop statement which are FOR LOOP and WHILE LOOP. These are called the iteration schemes. However, it is possible to define a loop without using these iteration schemes. In that case we need to use WAIT statement.
advertisement
advertisement

4. What is the use of FOR loop?
a) To repeat the statement finite number of times
b) To repeat the statement until any condition holds true
c) To repeat the statements for infinite time
d) To repeat statements inside until any condition is false
View Answer

Answer: a
Explanation: FOR LOOP iteration scheme is used to repeat the statements enclosed within a fixed number of times. There is no condition used in the for loop, but a limit is set which must be static and the loop will run only given number of times.

5. Which of the following is correct syntax for defining FOR LOOP?
a)

Note: Join free Sanfoundry classes at Telegram or Youtube
    label : FOR LOOP loop_specification
     sequential_statements;
     ….
     END LOOP label;

b)

advertisement
    label : FOR loop_specification LOOP
     sequential_statements;
     ….
     END FOR LOOP;

c)

advertisement
    label : FOR LOOP loop_specification
     sequential_statements;
     ….
     END FOR LOOP;

d)

    label : FOR loop_specification LOOP
     sequential_statements;
     ….
     END LOOP label;
View Answer
Answer: d
Explanation: The FOR LOOP is defined by using an optional label followed by a keyword FOR. After which the specification is defined which is the number of times loop should execute. This specification is followed by keyword LOOP. After this we can start writing sequential statements and the loop is ended with END LOOP and an optional label.
 
 

6. What is the use of WHILE loop?
a) To repeat the statement finite number of times
b) To repeat the statement until any condition holds true
c) To repeat the statements for infinite time
d) To repeat statements inside until any condition is false
View Answer

Answer: b
Explanation: WHILE LOOP is repeated until a condition no longer holds. The condition is first tested and if it is found to be true then the loop iteration starts. With the end of iteration, the condition is again tested and the process continues until the condition is not false.

7. Which of the following is correct syntax for WHILE LOOP?
a)

   label: WHILE LOOP specification IS
    sequential_statements;
    END LOOP;

b)

    label: WHILE LOOP condition
    sequential_statements;
    END LOOP label;

c)

    label: WHILE condition LOOP
    sequential_statements;
    END LOOP label;

d)

   label: WHILE specification LOOP
    sequential_statements;
    END LOOP;
View Answer
Answer: c
Explanation: WHILE loop can be declared by using an optional label followed by the keyword WHILE. After writing WHILE, the condition must be written, the loop will execute until the condition will be true. Otherwise, the loop will not execute.
 
 

8. What does the next statement in loops do?
a) Skips the current iteration
b) Starts the next loop by ending the current
c) Exits the loop
d) Skips the next line of the loop
View Answer

Answer: a
Explanation: The next statement is used to skip the current iteration and start the next iteration of the same loop. This statement passes the control the statement which is enclosing the innermost loop. This statement is useful when one needs to perform some action for every value except one.

9. What is the syntax to use the NEXT statement?
a) NEXT condition loop_label
b) NEXT loop_label WHEN condition
c) loop_label NEXT WHEN condition
d) loop_label NEXT condition
View Answer

Answer: b
Explanation: The next statement can be used by using the keyword NEXT followed by the loop label so that it can execute the next iteration by passing the control to the statement containing loop_label. Loop label is followed by keyword WHEN and one condition so that the iteration is skipped only when the condition is true. If there is no label given to the loop then there is no need to write the label in the NEXT statement. In that case, next statement applies to the innermost enclosing loop.

10. It is not possible to write an infinite loop in VHDL.
a) True
b) False
View Answer

Answer: a
Explanation: Since VHDL is a hardware description language, so unlike traditional programming languages we can’t write an infinite loop. Actually PROCESS itself is an infinite loop that executes whenever any signal of sensitivity list changes. It is necessary to add some exit statement or a condition in every loop.

Sanfoundry Global Education & Learning Series – VHDL.

To practice all areas of VHDL, here is complete set of 1000+ Multiple Choice Questions and Answers.

If you find a mistake in question / option / answer, kindly take a screenshot and email to [email protected]

advertisement
advertisement
Subscribe to our Newsletters (Subject-wise). Participate in the Sanfoundry Certification contest to get free Certificate of Merit. Join our social networks below and stay updated with latest contests, videos, internships and jobs!

Youtube | Telegram | LinkedIn | Instagram | Facebook | Twitter | Pinterest
Manish Bhojasia - Founder & CTO at Sanfoundry
Manish Bhojasia, a technology veteran with 20+ years @ Cisco & Wipro, is Founder and CTO at Sanfoundry. He lives in Bangalore, and focuses on development of Linux Kernel, SAN Technologies, Advanced C, Data Structures & Alogrithms. Stay connected with him at LinkedIn.

Subscribe to his free Masterclasses at Youtube & discussions at Telegram SanfoundryClasses.