Search icon CANCEL
Subscription
0
Cart icon
Cart
Close icon
You have no products in your basket yet
Save more on your purchases!
Savings automatically calculated. No voucher code required
Arrow left icon
All Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Newsletters
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
C# and Algorithmic Thinking for the Complete Beginner

You're reading from  C# and Algorithmic Thinking for the Complete Beginner

Product type Book
Published in Jun 2024
Publisher Packt
ISBN-13 9781836205630
Pages 916 pages
Edition 1st Edition
Languages
Author (1):
Aristides Bouras Aristides Bouras
Profile icon Aristides Bouras
Toc

Table of Contents (11) Chapters close

Preface 1. Part I Introductory Knowledge 2. Part II Getting Started with C# 3. Part III Sequence Control Structures 4. Part IV Decision Control Structures 5. Part V Loop Control Structures 6. Part VI Data Structures in C# 7. Part VII Subprograms 8. Part VIII Object-Oriented Programming 9. Part IX Files 10. Some Final Words from the Author

Chapter 17
The Dual-Alternative Decision Structure

17.1 The Dual-Alternative Decision Structure

In contrast to the single-alternative decision structure, this type of decision control structure includes a statement or block of statements on both paths.

Image

If Boolean_Expression evaluates to true, the statement or block of statements 1 is executed; otherwise, the statement or block of statements 2 is executed.

The general form of the C# statement is

if (Boolean_Expression) {
A statement or block of statements 1
}
else {
A statement or block of statements 2
}

In the next example, the message “You are an adult” is displayed when the user enters a value greater than or equal to 18. The message “You are underage!” is displayed otherwise.

 project_17.1
int age;
 
Console.Write("Enter your age: ");
age = Convert.ToInt32(Console.ReadLine());
 
if (age >= 18) {
Console.WriteLine("You are an adult!");
}
else {
Console.WriteLine(&quot...
lock icon The rest of the chapter is locked
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime