FREE! Click here to Join FunTrivia. Thousands of games, quizzes, and lots more!
Quiz about Strange Loops
Quiz about Strange Loops

Strange Loops Trivia Quiz


Loops are a key concept in computer programming so I thought I'd write a quiz on them. (In this quiz I sometimes specify a programming language in each question although the construct/idea may be very similar, or even the same, in other languages)

A multiple-choice quiz by The_Cyclist. Estimated time: 4 mins.
  1. Home
  2. »
  3. Quizzes
  4. »
  5. Science Trivia
  6. »
  7. Computers
  8. »
  9. Software and Programming

Author
The_Cyclist
Time
4 mins
Type
Multiple Choice
Quiz #
383,946
Updated
Aug 19 23
# Qns
10
Difficulty
Average
Avg Score
7 / 10
Plays
200
- -
Question 1 of 10
1. In the context of computer programming what is a loop? Hint


Question 2 of 10
2. In many languages, including C, the body of a loop must be enclosed by what character? Hint


Question 3 of 10
3. Sometimes the programmer may wish the loop to stop before it has finished executing completely. What word is used in many languages, including Javascript, to end the loop early? Hint


Question 4 of 10
4. When writing a loop in the Python programming language each line of the content of the loop must be indented by the same amount.


Question 5 of 10
5. In the language Ruby, which command can be used to tell the program that the loop body has finished? Hint


Question 6 of 10
6. When creating a loop, the programmer usually needs to be careful that their loop does not run forever. What is the term used to describe a loop which does not stop? Hint


Question 7 of 10
7. Instead of using a for loop to work through items in a collection the language Java has a built in method that can be used instead. What is this method called? Hint


Question 8 of 10
8. The language PHP, amongst others, has a loop known as a 'do ... while' loop. How does this differ from a regular 'while' loop? Hint


Question 9 of 10
9. A for loop in the COBOL language starts with which statement? Hint


Question 10 of 10
10. In which of the following languages does a possible syntax for creating a loop include the keyword 'LOOP'? Hint



(Optional) Create a Free FunTrivia ID to save the points you are about to earn:

arrow Select a User ID:
arrow Choose a Password:
arrow Your Email:




Quiz Answer Key and Fun Facts
1. In the context of computer programming what is a loop?

Answer: A piece of code containing a group of statements that is written once but can be executed multiple times

Loops are a key constituent of control flow in a computer program. They make writing programs less time consuming as the programmer does not have to write out the same code multiple times. All high level programming languages (such as C, Java, Python etc) have ways of writing loops.
2. In many languages, including C, the body of a loop must be enclosed by what character?

Answer: Curly braces

Most languages have a means of signalling the start and end of the code to be executed by the loop. This code is also referred to as the 'body' of the loop. In many languages, including C, the body of the loop is surrounded by curly braces. These tell the program compiler where the loop body starts and ends. Usually missing out one or both of the curly braces will result in an error when the program is compiled.
3. Sometimes the programmer may wish the loop to stop before it has finished executing completely. What word is used in many languages, including Javascript, to end the loop early?

Answer: break

JavaScript first appeared in 1995 and was designed by Brendan Eich. Despite its name the language is not connected with the Java language. The break clause is included in a loop body where the programmer wishes the loop to stop executing and for the program to move onto the rest of the code.

It has been argued by some academics that breaking loops early is not required and should not be done. This approach influenced the PASCAL language which did not include a means of exiting a loop early.
4. When writing a loop in the Python programming language each line of the content of the loop must be indented by the same amount.

Answer: True

The Python language was developed by Guido van Rossum and first appeared in 1991. Python doesn't use a symbol or character to mark the start and end of blocks of code such as loop bodies. Instead it uses 'whitespace' or indentation in order to mark code blocks.

There is no set format for how much each block must be indented but each line in the same block must be indented by the same amount to signal that it is part of the same block.
5. In the language Ruby, which command can be used to tell the program that the loop body has finished?

Answer: end

Ruby first appeared in 1995 and was created in Japan by Yukihiro Matsumoto. While there are symbols in Ruby that can be used to mark the start and end of a loop body the programer can also use commands instead, such as the 'end' command which is used to show that the loop body is finished.
6. When creating a loop, the programmer usually needs to be careful that their loop does not run forever. What is the term used to describe a loop which does not stop?

Answer: Infinite loop

Infinite loops are a problem as they never stop executing and so the program will never move on to and execute the rest of the code. This occurs because the condition for breaking the loop is set so that it will never be met. In older programming languages infinite loops would often cause the whole system to stop working but most modern system usually have a means of allowing the user to terminate the problematic code.

Although infinite loops are usually a problem, there are occasionally situations in which they are built intentionally An example of this is in an old fashioned games console with no operating system where the game will never 'exit' and will continue to run until the media containing the game is removed.
7. Instead of using a for loop to work through items in a collection the language Java has a built in method that can be used instead. What is this method called?

Answer: Iterator

Java first appeared in 1995 and was designed by James Gosling.

Working through items in a collection is frequently used in programming. Collections are groups of information such as arrays or lists. Working through each item is called iterating, hence the name of the Java function. The use of the function saves programmers time as they do not have to construct a loop to work through the list and they can use the built in function instead. The iterator function can also remove an item from a collection as well as just access it.
8. The language PHP, amongst others, has a loop known as a 'do ... while' loop. How does this differ from a regular 'while' loop?

Answer: It checks the condition at the end rather than the start of the loop

PHP was originally created by Rasmus Lerdorf in 1994, the language is widely used on the web and can be integrated with HTML. The 'do ... while' loop is a loop in which the condition, the statement that controls whether the loop should execute, is checked at the end rather than the beginning of the loop code.

This means that even if the condition is false the loop code will execute at least once.
9. A for loop in the COBOL language starts with which statement?

Answer: Perform Varying

The name COBOL derives from the name common business-oriented language and was developed in 1959 by a team of computer scientists working on a project for the US Department of Defense. The syntax of COBOL was designed to be 'English like', the idea being that it would be easier to read by humans than other languages of the time.

This is why many of its constructs are quite wordy. The 'perform varying' statement is usually coupled with a 'until' statement and means that the body of the loop will be performed until the condition in the 'until' statement is met.
10. In which of the following languages does a possible syntax for creating a loop include the keyword 'LOOP'?

Answer: Visual BASIC

BASIC stands for Beginner's All-purpose Symbolic Instruction Code. The language first appeared in 1964 and was designed by John George Kemeny and Thomas Eugene Kurtz. BASIC was very popular in the 1970s with the advent of the microcomputers, which were affordable enough for people to have at home. BASIC was the language of choice for these computers as it was small enough for the microcomputers while being a high-level language and therefore simpler for the user.

Visual BASIC is a Microsoft version of BASIC, particularly well known for being the macro language used in Microsoft Office. While uncommonly used, DO... LOOP is a legitimate way of writing loops in that language.
Source: Author The_Cyclist

This quiz was reviewed by FunTrivia editor rossian before going online.
Any errors found in FunTrivia content are routinely corrected through our feedback system.
11/21/2024, Copyright 2024 FunTrivia, Inc. - Report an Error / Contact Us