Skip to content

Latest commit

 

History

History
31 lines (22 loc) · 1.36 KB

File metadata and controls

31 lines (22 loc) · 1.36 KB

Chapter 6.2. Nested Loops – Exam Problems

In the previous chapter we analysed nested loops and how to use them to draw different kinds of figures on the console. We learned how to print figures with different sizes, thinking of an appropriate logic to construct them using single and nestedfor loops in combination with various calculations and program logic:

for (var r = 1; r <= 5; r++)
{
   Console.Write("*");
   for (var c = 1; c < 5; c++)
      Console.Write(" *");
   Console.WriteLine();
}

We also learned about the new string constructor, which lets you print a character a number of times defined by us:

string printMe = new string('*', 5);

Exam Problems

Let's solve several exam problems related to nested loops to practice what we learned and to further develop our algorithmic thinking: