X1321: Select The Best Answer

Railroad diagrams, also known as syntax diagrams, are a visual way to represent the grammar of a programming language. To use it, you trace the diagram as if it was a railroad from left to right. The ovals represent terminals (exact characters or keywords) on the input. The rectangles represent non-terminals, typically defined by other diagrams or simply abstracted out for presentation.

for railroad diagram

The image below is a railroad diagram for the for loop in Java.

railroad diagram for loop

To process the diagram, follow the path:

  • Move along the path from left to right.
  • When you encounter a terminal (oval), match it exactly in your code.
  • When you encounter a non-terminal (rectangle), look for another diagram as the definition (think of a method call).
  • When the path loops back on itself, it indicates repetition. Follow the loop as many times as needed.

Question

Using the diagram above, is the code shown below a valid for loop?

for (;;);

You may assume that the ; at the end of a line is a valid representation for a statement.

Your Answer:

Select one answer:


Practice a different Java exercise

Feedback

Your feedback will appear here when you check your answer.