Search icon CANCEL
Subscription
0
Cart icon
Your Cart (0 item)
Close icon
You have no products in your basket yet
Arrow left icon
Explore Products
Best Sellers
New Releases
Books
Videos
Audiobooks
Learning Hub
Conferences
Free Learning
Arrow right icon
Arrow up icon
GO TO TOP
Fundamentals for Self-Taught Programmers

You're reading from   Fundamentals for Self-Taught Programmers Embark on your software engineering journey without exhaustive courses and bulky tutorials

Arrow left icon
Product type Paperback
Published in Apr 2023
Publisher Packt
ISBN-13 9781801812115
Length 254 pages
Edition 1st Edition
Languages
Tools
Arrow right icon
Author (1):
Arrow left icon
Jasmine Greenaway Jasmine Greenaway
Author Profile Icon Jasmine Greenaway
Jasmine Greenaway
Arrow right icon
View More author details
Toc

Table of Contents (20) Chapters Close

Preface 1. Part 1: Software Engineering Basics
2. Chapter 1: Defining Software Engineering FREE CHAPTER 3. Chapter 2: The Software Engineering Life Cycle 4. Chapter 3: Roles in Software Engineering 5. Part 2: Introduction to Programming
6. Chapter 4: Programming Languages and Introduction to C# 7. Chapter 5: Writing Your First C# Program 8. Chapter 6: Data Types in C# 9. Chapter 7: Flow Control in C# 10. Chapter 8: Introduction to Data Structures, Algorithms, and Pseudocode 11. Chapter 9: Applying Algorithms in C# 12. Chapter 10: Object-Oriented Programming 13. Part 3: Software Engineering – the Profession
14. Chapter 11: Stories from Prominent Job Roles in Software Development 15. Chapter 12: Coding Best Practices 16. Chapter 13: Tips and Tricks to Kickstart Your Software Engineering Career 17. Assessments 18. Index 19. Other Books You May Enjoy

Introduction to if statements

Software engineers write conditions based on certain criteria to alter the flow of code. They do this by writing code that performs different tasks based on whether that condition evaluates to true or false. One of the most common ways to create these options, or branches of code, is with the if statement with the following syntax:

Figure 7.1 – Identifying parts of an if statement

Figure 7.1 – Identifying parts of an if statement

The code between the curly braces of an if statement will only run if the condition is true. If it’s false, then the code will be ignored. Let’s apply this if statement to the end of the MyBudget application, where we evaluate if we have enough for the book in the canAffordBook Boolean value. If we do, we’ll subtract the price of the book from the balance:

decimal bookPrice = 25;
bool canAffordBook = balance > bookPrice;
if (canAffordBook)
{
    Console.WriteLine("You can afford to buy the...
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 $19.99/month. Cancel anytime
Banner background image