{"id":13574,"date":"2020-07-24T14:34:09","date_gmt":"2020-07-24T21:34:09","guid":{"rendered":"https:\/\/careerkarma.com\/blog\/?p=13574"},"modified":"2023-12-01T03:56:04","modified_gmt":"2023-12-01T11:56:04","slug":"c-plus-plus-if-else","status":"publish","type":"post","link":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/","title":{"rendered":"If Else in C++: A Step-By-Step Guide"},"content":{"rendered":"\n<p><em><code>If...else<\/code> is a conditional statement in C++. The C++ <code>if<\/code> statement runs a block of code if a condition is met. An <code>if...else<\/code> statement functions the same way but runs a second block of code if the condition is not met. <code>If<\/code> and <code>if...else<\/code> statements can be nested.<\/em><\/p>\n\n\n\n<hr class=\"wp-block-separator\"\/>\n\n\n\n<p>Conditional statements are an essential part of every programming language. Conditional statements allow developers to run code based on whether a particular condition is met in a program.<\/p>\n\n\n\n<p>In C++, <em><code>if<\/code> <\/em>and<em> <\/em><code>if \u2026 else<\/code> statements evaluate whether a statement is true or false and only run a block of code if the statement evaluates to true.<\/p>\n\n\n\n<p>This tutorial will discuss, using examples, the basics of C++ conditional statements and how to write <em><code>if<\/code><\/em>, <em><code>if \u2026 else<\/code><\/em>, and <em><code>else if<\/code><\/em> statements in C++. By the end of this tutorial, you\u2019ll be an expert at using these statements in C++.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C++ Conditional Statements<\/h2>\n\n\n\n<p>Developers use conditional statements to define the condition(s) on which a block of code will run. Whether a block of code in a conditional statement will run depends on whether a certain condition or set of conditions are met. Here are a few examples where conditional statements may be used:<\/p>\n\n\n\n<ul class=\"wp-block-list\"><li>If a shopper has enough money in their account, a payment should be processed; if the shopper has insufficient funds, the payment should be declined.<\/li><li>If a customer is over the age of 17, they should be allowed to see a movie; if not, they should be denied entry to the movie.<\/li><li>If a bakery has less than 15 bags of flour in stock, a new case of flour should be ordered; if not, nothing should happen.<\/li><\/ul>\n\n\n\n<p>In these cases, a certain action should only be performed if a condition is met. That\u2019s where <em><code>if<\/code><\/em> and <em><code>if \u2026 else<\/code><\/em> statements come in. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C++ <em>if<\/em> Statement<\/h2>\n\n\n\n<p>The C++ <em><code>if<\/code> <\/em>statement evaluates whether an expression is true or false. If the expression evaluates to true, the program executes the code in the conditional statement; otherwise, the program does not execute the code in the conditional statement.&nbsp;&nbsp;&nbsp;<\/p>\n\n\n\n<p>Here\u2019s the syntax for an <em><code>if<\/code> <\/em>statement: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>if (expression) {\n\t\/\/ Code here\n}<\/pre><\/div>\n\n\n\n<p>Let\u2019s walk through an example to illustrate how <em><code>if<\/code> <\/em>statements work in C++. Suppose we are writing a program that calculates whether a bakery should order a new case of flour. If there are fewer than 15 bags of flour in inventory, a new case should be ordered.<\/p>\n\n\n\n<p>We could use the following code to accomplish this task:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &lt;iostream&gt;\ninclude namespace std;\nint main() {\n\tint flourBagCount = 12;\n \tif (flourBagCount &lt; 15) {\n\t\tcout &lt;&lt; \"There are not enough bags of flour in inventory.\"\n\t}\n}<\/pre><\/div>\n\n\n\n<p>When we run this code, the following is printed to the console: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>There are not enough bags of flour in inventory.<\/pre><\/div>\n\n\n\n<p>Let\u2019s break down this example. First we declare a variable called <code>flourBagCount<\/code> that stores the number of bags of flour we have in inventory. Then we initialize an <em><code>if<\/code> <\/em>statement that checks whether there are fewer than 15 bags of flour in inventory.<\/p>\n\n\n\n<p>If the variable <code>flourBagCount<\/code> is less than 15, the message <code>There are not enough bags in inventory.<\/code> is printed to the console; otherwise, nothing happens. In this case, <code>flourBagCount<\/code> is equal to 12, which is less than 15, so the program executes the code contained within the <em><code>if<\/code> <\/em>statement. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C++ <em>if \u2026 else<\/em> Statement<\/h2>\n\n\n\n<p>When you\u2019re working with <em><code>if<\/code> <\/em>statements, you may want your program to do something besides move on if the<em> <\/em>statement evaluates to false.<\/p>\n\n\n\n<p><em><code>if \u2026 else<\/code> <\/em>statements, like <em><code>if<\/code> <\/em>statements, check for a condition. If that condition is met, the program executes the contents of the <em><code>if<\/code><\/em> portion of the statement. However, unlike <em><code>if<\/code><\/em> statements, in <em><code>if \u2026 else<\/code> <\/em>statements, if the condition is not met, the contents of the <em>else <\/em>statement execute.&nbsp;<\/p>\n\n\n\n<p>Here\u2019s the syntax for an <em><code>if \u2026 else<\/code> <\/em>statement: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>if (expression) {\n\t\/\/ Run code\n} else {\n\t\/\/ Run other code\n}<\/pre><\/div>\n\n\n\n<p>Let\u2019s take our bakery example from above. In our example, if there are fewer than 15 bags in stock, the program prints a message to the console telling the baker that there are not enough bags of flour in inventory. However, if there are enough bags of flour in inventory, nothing happens.<\/p>\n\n\n\n<p>Suppose that we want a message to appear notifying the baker that there are enough bags of flour in inventory if there are 15 or more bags in stock. That\u2019s where we could use an <em><code>if \u2026 else<\/code><\/em> statement. The following code would tell the program to print a certain message to the console if there are enough bags of flour in inventory: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &lt;iostream&gt;\ninclude namespace std;\nint main() {\n\tint flourBagCount = 16;\n \tif (flourBagCount &lt; 15) {\n\t\tcout &lt;&lt; \"There are not enough bags of flour in inventory.\"\n\t} else {\n\t\tcout &lt;&lt; \"There are enough bags of flour in inventory.\"\n\t}\n}<\/pre><\/div>\n\n\n\n<p>Our code returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>There are enough bags of flour in inventory.<\/pre><\/div>\n\n\n\n<p>In this example, we changed the value of <code>flourBagCount<\/code> to 16. We also added an <em><code>else<\/code> <\/em>statement to our code.<\/p>\n\n\n\n<p>Because <code>flourBagCount<\/code> is not less than 15, our <em><code>if<\/code> <\/em>statement evaluates to false. This means that our program executes the contents of our <em><code>else<\/code> <\/em>statement instead. As a result, our program prints the text, <code>There are enough bags of flour in inventory.<\/code> to the console. <\/p>\n\n\n\n<p>C++ allows for nested if statements, which is simply an <code>if<\/code> or <code>if...else<\/code> statement inside of another statement.  However, often a cleaner way to handle this need is often <code>else if<\/code> statements. <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">C++ <em>else if <\/em>Statement<\/h2>\n\n\n\n<p>We have already discussed how to use an <em><code>if<\/code> <\/em>statement to code a programmed response if a condition evaluates to true, and how to use an <em><code>else<\/code> <\/em>block to run certain code if a preceding <em><code>if<\/code><\/em> statement evaluates to false. But what if we want to check for multiple conditions and execute a block of statements if any of those conditions are true?<\/p>\n\n\n\n<p>To check for multiple conditions in a program, we need to use a nested <em><code>else if<\/code><\/em> statement. Here\u2019s the syntax of a nested<em> <code>else if<\/code><\/em> statement in C++: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>if (expressionOne) {\n\t\/\/ Code to run if condition is true\n} else if (expressionTwo) {\n\t\/\/ Code to run if condition is false and expressionTwo is true\n} else {\n\t\/\/ Code to run if all test expressions are false\n}<\/pre><\/div>\n\n\n\n<p>Let\u2019s walk through an example to discuss how the <em><code>else if<\/code> <\/em>statement works.<\/p>\n\n\n\n<p>Suppose we want to add a message to our bakery program from earlier that notifies our baker when the number of bags of flour in stock is equal to or greater than 15 and is equal to or less than 20. We want our program to do the following:<\/p>\n\n\n\n<ol class=\"wp-block-list\"><li>If there are over 20 bags of flour in stock, the program should print out a message that says, <code>There are enough bags of flour in inventory.<\/code><\/li><li>If there are between 15 and 20 bags of flour in stock, the program should print out a message that says, <code>A new order for flour should be placed soon.<\/code><\/li><li>If there are fewer than 15 bags of flour in inventory, the program should print out a message that says, <code>There are not enough bags of flour in inventory.<\/code>&nbsp;<\/li><\/ol>\n\n\n\n<p>We could use the following code for this program:<\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>#include &lt;iostream&gt;\ninclude namespace std;\nint main() {\n\tint flourBagCount = 16;\n \tif (flourBagCount &gt; 20) {\n\t\tcout &lt;&lt; \"There are enough bags of flour in inventory.\"\n\t} else if (flourBagCount &lt;= 20 &amp;&amp; flourBagCount &gt;= 15) {\n\t\tcout &lt;&lt; \"A new order for flour should be placed soon.\"\n\t} else {\n\t\tcout &lt;&lt; \"There are not enough bags of flour in inventory.\"\n\t}\n}<\/pre><\/div>\n\n\n\n<p>Our code returns: <\/p>\n\n\n\n<div class=\"wp-block-codemirror-blocks-code-block code-block\"><pre>A new order for flour should be placed soon.<\/pre><\/div>\n\n\n\n<p>In this example, our program checks for two conditions and includes an <em><code>else<\/code> <\/em>statement that executes if those two conditions both evaluate to false.<\/p>\n\n\n\n<p>In the first conditional statement in the above code, our program checks to see if the value of <code>flourBagCount<\/code> is over 20. If it is, the message <code>There are enough bags of flour in inventory.<\/code> is printed to the console.<\/p>\n\n\n\n<p>If this statement evaluates to false, the <em><code>else if<\/code><\/em> statement is evaluated. In this example, the <em><code>else if<\/code> <\/em>statement checks to see whether the value of <code>flourBagCount<\/code> is equal to or less than 20 and equal to or greater than 15. If both these statements are true, the message <code>A new order for flour should be placed soon.<\/code> is printed to the console. This was the case&#8211;and outcome&#8211;of the above example.<\/p>\n\n\n\n<p>If both of the <em><code>if<\/code> <\/em>statements in our code (<em><code>if<\/code><\/em> and <em><code>else if<\/code><\/em>) evaluate to false, our program executes the code in the <em><code>else<\/code> <\/em>statement. If this is the case, our program prints out the message, <code>There are not enough bags of flour in inventory.<\/code> <\/p>\n\n\n\n<h2 class=\"wp-block-heading\">Conclusion<\/h2>\n\n\n\n<p>You can use <em><code>if<\/code> <\/em>and <em><code>if \u2026 else<\/code><\/em> statements to control the flow of a program in C++.<\/p>\n\n\n\n<p><em><code>if<\/code> <\/em>statements evaluate whether a condition is true and execute certain code if so. <em><code>else if<\/code><\/em> statements evaluate whether a second condition is true and execute certain code if so. <em><code>else<\/code> <\/em>statements execute certain code if none of the specified conditions in an <em><code>if<\/code> <\/em>statement evaluate to true.<\/p>\n\n\n\n<p>This tutorial discussed, with examples, how to use <em><code>if<\/code><\/em>, <em><code>if \u2026 else<\/code><\/em>, and <em><code>else if<\/code> <\/em>statements in C++. Now you\u2019re ready to start using these C++ conditional statements like a professional developer.<\/p>\n","protected":false},"excerpt":{"rendered":"If...else is a conditional statement in C++. The C++ if statement runs a block of code if a condition is met. An if...else statement functions the same way but runs a second block of code if the condition is not met. If and if...else statements can be nested. Conditional statements are an essential part of&hellip;","protected":false},"author":240,"featured_media":13576,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[17291],"tags":[],"class_list":{"0":"post-13574","1":"post","2":"type-post","3":"status-publish","4":"format-standard","5":"has-post-thumbnail","7":"category-c-plus-plus"},"acf":{"post_sub_title":"","sprint_id":"","query_class":"C++","school_sft":"","parent_sft":"","school_privacy_policy":"","has_review":null,"is_sponser_post":"","is_guest_post":""},"yoast_head":"<!-- This site is optimized with the Yoast SEO Premium plugin v27.0 (Yoast SEO v27.0) - https:\/\/yoast.com\/product\/yoast-seo-premium-wordpress\/ -->\n<title>If Else in C++: A Step-By-Step Guide | Career Karma<\/title>\n<meta name=\"description\" content=\"The conditional statements (\u201cif\u201d and \u201cif \u2026 else\u201d) control the flow of a C++ program. On Career Karma, learn how to use these statements.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"If Else in C++: A Step-By-Step Guide\" \/>\n<meta property=\"og:description\" content=\"The conditional statements (\u201cif\u201d and \u201cif \u2026 else\u201d) control the flow of a C++ program. On Career Karma, learn how to use these statements.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/\" \/>\n<meta property=\"og:site_name\" content=\"Career Karma\" \/>\n<meta property=\"article:publisher\" content=\"http:\/\/facebook.com\/careerkarmaapp\" \/>\n<meta property=\"article:published_time\" content=\"2020-07-24T21:34:09+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2023-12-01T11:56:04+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/laptop-macbook-pro-office-computer-18105.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1020\" \/>\n\t<meta property=\"og:image:height\" content=\"680\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"James Gallagher\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@career_karma\" \/>\n<meta name=\"twitter:site\" content=\"@career_karma\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"James Gallagher\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/\"},\"author\":{\"name\":\"James Gallagher\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"headline\":\"If Else in C++: A Step-By-Step Guide\",\"datePublished\":\"2020-07-24T21:34:09+00:00\",\"dateModified\":\"2023-12-01T11:56:04+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/\"},\"wordCount\":1198,\"commentCount\":0,\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/laptop-macbook-pro-office-computer-18105.jpg\",\"articleSection\":[\"C++ Programming\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/\",\"name\":\"If Else in C++: A Step-By-Step Guide | Career Karma\",\"isPartOf\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/laptop-macbook-pro-office-computer-18105.jpg\",\"datePublished\":\"2020-07-24T21:34:09+00:00\",\"dateModified\":\"2023-12-01T11:56:04+00:00\",\"author\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\"},\"description\":\"The conditional statements (\u201cif\u201d and \u201cif \u2026 else\u201d) control the flow of a C++ program. On Career Karma, learn how to use these statements.\",\"breadcrumb\":{\"@id\":\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#primaryimage\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/laptop-macbook-pro-office-computer-18105.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/laptop-macbook-pro-office-computer-18105.jpg\",\"width\":1020,\"height\":680},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Blog\",\"item\":\"https:\/\/careerkarma.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"C++ Programming\",\"item\":\"https:\/\/careerkarma.com\/blog\/c-plus-plus\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"If Else in C++: A Step-By-Step Guide\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#website\",\"url\":\"https:\/\/careerkarma.com\/blog\/\",\"name\":\"Career Karma\",\"description\":\"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/careerkarma.com\/blog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94\",\"name\":\"James Gallagher\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"contentUrl\":\"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg\",\"caption\":\"James Gallagher\"},\"description\":\"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.\",\"url\":\"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/\"}]}<\/script>\n<!-- \/ Yoast SEO Premium plugin. -->","yoast_head_json":{"title":"If Else in C++: A Step-By-Step Guide | Career Karma","description":"The conditional statements (\u201cif\u201d and \u201cif \u2026 else\u201d) control the flow of a C++ program. On Career Karma, learn how to use these statements.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/","og_locale":"en_US","og_type":"article","og_title":"If Else in C++: A Step-By-Step Guide","og_description":"The conditional statements (\u201cif\u201d and \u201cif \u2026 else\u201d) control the flow of a C++ program. On Career Karma, learn how to use these statements.","og_url":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/","og_site_name":"Career Karma","article_publisher":"http:\/\/facebook.com\/careerkarmaapp","article_published_time":"2020-07-24T21:34:09+00:00","article_modified_time":"2023-12-01T11:56:04+00:00","og_image":[{"width":1020,"height":680,"url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/laptop-macbook-pro-office-computer-18105.jpg","type":"image\/jpeg"}],"author":"James Gallagher","twitter_card":"summary_large_image","twitter_creator":"@career_karma","twitter_site":"@career_karma","twitter_misc":{"Written by":"James Gallagher","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#article","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/"},"author":{"name":"James Gallagher","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"headline":"If Else in C++: A Step-By-Step Guide","datePublished":"2020-07-24T21:34:09+00:00","dateModified":"2023-12-01T11:56:04+00:00","mainEntityOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/"},"wordCount":1198,"commentCount":0,"image":{"@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/laptop-macbook-pro-office-computer-18105.jpg","articleSection":["C++ Programming"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/","url":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/","name":"If Else in C++: A Step-By-Step Guide | Career Karma","isPartOf":{"@id":"https:\/\/careerkarma.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#primaryimage"},"image":{"@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#primaryimage"},"thumbnailUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/laptop-macbook-pro-office-computer-18105.jpg","datePublished":"2020-07-24T21:34:09+00:00","dateModified":"2023-12-01T11:56:04+00:00","author":{"@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94"},"description":"The conditional statements (\u201cif\u201d and \u201cif \u2026 else\u201d) control the flow of a C++ program. On Career Karma, learn how to use these statements.","breadcrumb":{"@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#primaryimage","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/laptop-macbook-pro-office-computer-18105.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/03\/laptop-macbook-pro-office-computer-18105.jpg","width":1020,"height":680},{"@type":"BreadcrumbList","@id":"https:\/\/careerkarma.com\/blog\/c-plus-plus-if-else\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Blog","item":"https:\/\/careerkarma.com\/blog\/"},{"@type":"ListItem","position":2,"name":"C++ Programming","item":"https:\/\/careerkarma.com\/blog\/c-plus-plus\/"},{"@type":"ListItem","position":3,"name":"If Else in C++: A Step-By-Step Guide"}]},{"@type":"WebSite","@id":"https:\/\/careerkarma.com\/blog\/#website","url":"https:\/\/careerkarma.com\/blog\/","name":"Career Karma","description":"Latest Coding Bootcamp News &amp; Career Hacks from Industry Insiders","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/careerkarma.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Person","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/e79364792443fbff794a144c67ec8e94","name":"James Gallagher","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/careerkarma.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","contentUrl":"https:\/\/careerkarma.com\/blog\/wp-content\/uploads\/2020\/01\/james-gallagher-150x150.jpg","caption":"James Gallagher"},"description":"James Gallagher is a self-taught programmer and the technical content manager at Career Karma. He has experience in range of programming languages and extensive expertise in Python, HTML, CSS, and JavaScript. James has written hundreds of programming tutorials, and he frequently contributes to publications like Codecademy, Treehouse, Repl.it, Afrotech, and others.","url":"https:\/\/careerkarma.com\/blog\/author\/jamesgallagher\/"}]}},"_links":{"self":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/13574","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/users\/240"}],"replies":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/comments?post=13574"}],"version-history":[{"count":0,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/posts\/13574\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media\/13576"}],"wp:attachment":[{"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/media?parent=13574"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/categories?post=13574"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/careerkarma.com\/blog\/wp-json\/wp\/v2\/tags?post=13574"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}