Introduction

Completed

Creating a code branch and iterating through a code block are essential capabilities for a developer. In C#, the if statement can be used to evaluate an expression and branch the execution path. The code block of a foreach statement can be used to iterate through each element of an array. Powerful and extensible applications can be created by combining the ability to iterate through an array with the ability to branch the execution path.

Suppose you're a teacher's assistant at a school. You've been working with a teacher to create an application that automates the grading process. Your C# programming skills have increased since you completed the initial version of your application. The teacher has asked you to update your application. The updates focus on using arrays, foreach statements, and if statements. The teacher also wants you to include extra credit assignments in your calculations of the final grades.

In this module, you'll be guided through the process of updating your Student Grading application. You'll use arrays to store student names and the scores of graded assignments, and you'll use foreach statements to iterate through array values. Each student's final grade will be calculated inside a foreach code block. You'll use an if statement to assign a final letter grade. Your completed application will output student grades using the teacher's score report specification.

By the end of this module, you'll have experience developing applications that use arrays, foreach statements, and if statements. You'll also be comfortable creating applications that efficiently process data using nested iteration and selection statements.

Note

This is a guided project module where you’ll complete an end-to-end project by following step-by-step instructions.

Learning objectives

In this module, you'll practice how to:

  • Use Visual Studio Code to develop a C# console application that uses foreach loops to access array data.
  • Use if statements to evaluate expressions and create code branches.

Prerequisites

  • Experience using Visual Studio Code to develop, build, and run C# console applications that include console I/O and access the methods of .NET classes.
  • Experience using if statements in C# to evaluate an expression and branch code accordingly.
  • Experience using a foreach loop to access elements of array variables.