Notice: This page requires JavaScript to function properly.
Please enable JavaScript in your browser settings or update your browser.
Learn Challenge: for Loop | Section
C# Basics
Sectionย 1. Chapterย 38
single

single

bookChallenge: for Loop

Swipe to show menu

Task

Swipe to start coding

Imagine you are buying several items in a shop. Each item costs the same amount, and you want to calculate the total cost of all items.

  • Initialize totalCost to 0.
  • The loop should start with i = 0 and run while i < quantity.
  • Add itemPrice to totalCost inside the loop.
  • Return totalCost at the end of the method.

Solution

Switch to desktopSwitch to desktop for real-world practiceContinue from where you are using one of the options below
Everything was clear?

How can we improve it?

Thanks for your feedback!

Sectionย 1. Chapterย 38
single

single

Ask AI

expand

Ask AI

ChatGPT

Ask anything or try one of the suggested questions to begin our chat

some-alt