Unix Shell Scripting Loops MCQs
Shell Scripting Loops MCQs : This section focuses on "Loops" in Shell Progamming in Unix. These Multiple Choice Questions (MCQ) should be practiced to improve the unix skills required for various interviews (campus interviews, walk-in interviews, company interviews), placements, entrance exams and other competitive examinations.
1. Which of the following loops is not available in shell?
A. The for loop
B. The until loop
C. The select loop
D. The foreach loop
View Answer
Ans : D
Explanation: The foreach loop is not available in shell.
2. The _______ loop executes the given commands until the given condition remains true.
A. For loop
B. While loop
C. until loop
D. Both B and C
View Answer
Ans : B
Explanation: The while loop executes the given commands until the given condition remains true.
3. Which of the following statements that are used to control shell loops?
A. break
B. continue
C. Both A and B
D. None of the above
View Answer
Ans : C
Explanation: Break and continue two statements that are used to control shell loops.
4. A loop may continue forever if the required condition is not met is known as ____________.
A. finite loop
B. infinite loop
C. simple loop
D. definate loop
View Answer
Ans : B
Explanation: A loop may continue forever if the required condition is not met is known as infinite loop.
5. Which of the following statement is used to terminate the execution of the entire loop?
A. continue
B. terminate
C. this
D. break
View Answer
Ans : D
Explanation: The break statement is used to terminate the execution of the entire loop.
6. What is the syntax of break command that can also be used to exit from a nested loop?
A. break
B. break loop
C. break n
D. break n+i
View Answer
Ans : C
Explanation: break n is the syntax of break command that can also be used to exit from a nested loop.
7. Which of the following statement is supported in unix shell?
A. case
B. Switch
C. switch...case
D. case...esac
View Answer
Ans : D
Explanation: Unix Shell supports case...esac statement.
8. Continue statment cannot be used in which loop?
A. For loop
B. until loop
C. while loop
D. case...esac
View Answer
Ans : D
Explanation: continue is used to skip the statments and can not be used with case...esac.
9. Which of the following statement causes the current iteration of the loop to exit, rather than the entire loop?
A. Continue
B. break
C. return
D. goto
View Answer
Ans : A
Explanation: The continue statement is similar to the break command, except that it causes the current iteration of the loop to exit, rather than the entire loop.
10. What is the syntax of continue statement?
A. continue
B. continue n
C. continue this
D. All of the above
View Answer
Ans : A
Explanation: Continue is the syntax used forcontinue statement.
Discussion