0
0
C Sharp (C#)programming~15 mins

While loop execution model in C Sharp (C#) - Mini Project: Build & Apply

Choose your learning style9 modes available
While loop execution model
📖 Scenario: You are helping a cashier count the number of customers entering a store until the store closes.
🎯 Goal: Build a program that uses a while loop to count customers until a closing time is reached.
📋 What You'll Learn
Create an integer variable called customers starting at 0
Create an integer variable called closingTime set to 5
Use a while loop with the condition customers < closingTime
Inside the loop, increase customers by 1 each time
Print the final number of customers after the loop ends
💡 Why This Matters
🌍 Real World
Counting customers or events until a certain limit is reached is common in stores, games, or data processing.
💼 Career
Understanding loops is essential for automating repetitive tasks and controlling program flow in software development.
Progress0 / 4 steps
1
Create the initial customer count
Create an integer variable called customers and set it to 0.
C Sharp (C#)
Need a hint?

Use int customers = 0; to start counting customers from zero.

2
Set the closing time
Create an integer variable called closingTime and set it to 5.
C Sharp (C#)
Need a hint?

Use int closingTime = 5; to set the limit for counting customers.

3
Write the while loop to count customers
Use a while loop with the condition customers < closingTime. Inside the loop, increase customers by 1.
C Sharp (C#)
Need a hint?

Use while (customers < closingTime) and inside the loop write customers++; to add one each time.

4
Print the final customer count
Write a Console.WriteLine statement to print the value of customers after the loop ends.
C Sharp (C#)
Need a hint?

Use Console.WriteLine(customers); to show the final count.