{"id":10533,"date":"2022-07-21T10:24:39","date_gmt":"2022-07-21T10:24:39","guid":{"rendered":"http:\/\/fastbitlab.com\/?p=10533"},"modified":"2024-10-08T17:15:32","modified_gmt":"2024-10-08T11:45:32","slug":"if-statement-in-c","status":"publish","type":"post","link":"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/","title":{"rendered":"Microcontroller Embedded C Programming Lecture 83| &#8216;if&#8217; statement"},"content":{"rendered":"<div class=\"boldgrid-section\" style=\"background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"container\">\n<div class=\"row\" style=\"padding-top: 35px; padding-bottom: 0px; background-image: linear-gradient(to left, #eeeeee, #eeeeee);\" data-bg-color-1=\"#EEEEEE\" data-bg-color-2=\"#EEEEEE\" data-bg-direction=\"to left\">\n<div class=\"col-md-1 col-sm-12 col-xs-12 col-lg-1\">\n<div class=\"boldgrid-shortcode\" data-imhwpb-draggable=\"true\">\n\n<\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<div class=\"col-md-10 col-sm-12 col-xs-12 col-lg-10\">\n<h1 class=\"\" style=\"text-align: center; font-size: 30px; border-width: 0px; line-height: 50px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000080;\"><strong>&#8216;if&#8217; statement<\/strong><\/span><\/h1>\n<div class=\"row bg-editor-hr-wrap\" style=\"border-width: 0px; margin-top: -25px;\">\n<div class=\"col-lg-12 col-md-12 col-xs-12 col-sm-12\">\n<div>\n<p>&nbsp;<\/p>\n<div class=\"bg-hr bg-hr-10 color2-color\" style=\"border-style: solid; border-width: 0px 0px 3px;\"><\/div>\n<p>&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<p class=\"\" style=\"font-size: 25px; border-width: 0px; line-height: 35px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #d9401a;\"><strong><span style=\"text-decoration: underline;\">Decision making statements in \u2018C\u2019<\/span><\/strong><\/span><\/p>\n<ul class=\"\" style=\"border-width: 0px; font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">When you are going to write some program, it will always be necessary that you will have to put some code which has to be executed only when a specific condition is satisfied.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">Your program has to take decision based on internal\/external events or conditions.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">For example, if the user presses a key, then execute \u2018this\u2019 set of statements or if the user doesn&#8217;t press any key, then execute \u2018that\u2019 set of statements.<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #000000;\">In embedded programming, let\u2019s take an example of water level indication and control program. If the sensor detects water level rising above the threshold, then the program executes the code to turn off the motor, otherwise program doesn&#8217;t turn off the motor. <\/span><\/li>\n<\/ul>\n<figure id=\"attachment_10536\" aria-describedby=\"caption-attachment-10536\" style=\"width: 543px\" class=\"wp-caption aligncenter\"><img fetchpriority=\"high\" decoding=\"async\" class=\"wp-image-10536 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/07\/Figure-1-28-1024x548.png\" alt=\"Figure 1. Decision making in \u2018C\u2019\" width=\"543\" height=\"290\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28-1024x548.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28-300x161.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28-768x411.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28-600x321.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28-1536x823.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28-500x268.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28-400x214.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28-800x428.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28-1200x643.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28.png 1619w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/><figcaption id=\"caption-attachment-10536\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 1. Decision making in \u2018C\u2019<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In &#8216;C&#8217;, there are 5 different ways to take decisions by making use of the below decision taking statements.<\/span><\/p>\n<ol class=\"color-4-text-contrast color4-background-color\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #d9401a;\">if Statement<\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"color: #d9401a;\"><a style=\"color: #d9401a;\" href=\"http:\/\/fastbitlab.com\/if-and-else-statement\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">if-else Statement<\/span><\/a><\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"color: #d9401a;\"><a style=\"color: #d9401a;\" href=\"http:\/\/fastbitlab.com\/microcontroller-embedded-c-programming-lecture-89-if-else-if-ladder-statements\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">if-else-if ladder<\/span><\/a><\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"color: #d9401a;\"><a style=\"color: #d9401a;\" href=\"http:\/\/fastbitlab.com\/microcontroller-embedded-c-programming-lecture-92-conditional-operator\/\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">Conditional Operators&nbsp;<\/span><\/a><\/span><\/li>\n<li style=\"font-weight: 400;\" aria-level=\"1\"><span style=\"font-weight: 400; color: #d9401a;\">Switch\/case Statement<\/span><\/li>\n<\/ol>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">We&#8217;ll understand each one of these statements one by one. So for this article, let&#8217;s understand the <\/span><b>if statement<\/b><span style=\"font-weight: 400;\">. It is very simple.<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 25px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 35px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #d9401a;\"><strong>Syntax of the &#8216;if&#8217; statement<\/strong><\/span><\/p>\n<figure id=\"attachment_10537\" aria-describedby=\"caption-attachment-10537\" style=\"width: 610px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-10537 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/07\/Figure-2-24-1024x577.png\" alt=\"Figure 2. Syntax of if statement\" width=\"610\" height=\"344\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-2-24-1024x577.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-2-24-300x169.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-2-24-768x433.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-2-24-600x338.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-2-24-1536x865.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-2-24-120x68.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-2-24-500x282.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-2-24-200x113.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-2-24-400x225.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-2-24-800x451.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-2-24-1200x676.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-2-24.png 1713w\" sizes=\"(max-width: 610px) 100vw, 610px\" \/><figcaption id=\"caption-attachment-10537\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 2. Syntax of if statement<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">If you want to use the<\/span><b> if statement<\/b><span style=\"font-weight: 400;\"> in your code, then you must use the standard keyword \u2018<\/span><b>if\u2019<\/b><span style=\"font-weight: 400;\"> along with the parentheses. So, if it is a standard keyword and inside the parentheses you have to write your <\/span><b>expression<\/b><span style=\"font-weight: 400;\">. The expression can be anything; it can be made up of relational operators, or it can be made up of arithmetic operators or bitwise operators. It can be anything.<\/span><span style=\"font-weight: 400;\">&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"font-size: 20px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><strong>Single Statement Execution of if statement&nbsp;<\/strong><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If the evaluation of this if(expression) is true(that is nonzero), then the statement that follows right after this &#8216;if&#8217; statement will be executed.&nbsp;<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If the evaluation of if(expression) is false(that is 0), then a statement that follows right after the if statement will be skipped. It will not be executed. So, the execution of this statement depends upon the evaluation of this expressions.&nbsp;<\/span><\/p>\n<p>https:\/\/www.traditionrolex.com\/27<\/p>\n<p class=\"\" style=\"font-size: 20px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><strong>Multiple statement execution of if statement<\/strong><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">&nbsp;if(expression) is true and if you want to execute multiple statements, then remember that you have to use the curly braces <strong>{}<\/strong>. The curly braces make the body of the if statement.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">If(expression) is true, then all these statements(like satament_1, statement_2) will be executed one by one. And if (expression) is false, then none of these statements will be executed, and the execution of this whole body will be skipped.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 25px; border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; line-height: 35px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #d9401a;\"><strong>Flowchart of the &#8216;if&#8217; statement<\/strong><\/span><\/p>\n<figure id=\"attachment_10538\" aria-describedby=\"caption-attachment-10538\" style=\"width: 676px\" class=\"wp-caption aligncenter\"><img decoding=\"async\" class=\"wp-image-10538 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/07\/Figure-3-20-1024x633.png\" alt=\"Figure 3. if statement flowchart\" width=\"676\" height=\"418\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-3-20-1024x633.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-3-20-300x185.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-3-20-768x474.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-3-20-600x371.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-3-20-1536x949.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-3-20-120x74.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-3-20-500x309.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-3-20-200x124.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-3-20-400x247.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-3-20-800x494.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-3-20-1200x741.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-3-20.png 1617w\" sizes=\"(max-width: 676px) 100vw, 676px\" \/><figcaption id=\"caption-attachment-10538\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 3. if statement flowchart<\/span><\/figcaption><\/figure>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">First, the expression will be evaluated. If the expression result is true, then the statement or statements will be executed. If it is false, then the statements will not be executed, and the execution control continues with the rest of the code of the program.&nbsp;<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 25px; border-width: 0px; line-height: 35px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #ff0000;\"><strong>Example<\/strong><\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #ff99cc;\">int<\/span> main(<span style=\"color: #ff99cc;\">void<\/span>)\r\n\r\n{\r\n\r\n<span style=\"color: #008000;\">&nbsp;uint8_t<\/span> myData = 20;\r\n\r\n<span style=\"color: #ff99cc;\"> if<\/span>(myData &gt; 40)\r\n\r\n  <span style=\"color: #ff00ff;\">printf<\/span>(\"value = %d\\n\", myData);\r\n\r\n<span style=\"color: #339966;\">\/*this statement is outside if block, so always execute *\/<\/span>\r\n\r\n myData++;\r\n\r\n<span style=\"color: #ff99cc;\"> return <\/span>0;\r\n\r\n}<\/pre>\n<p class=\"\" style=\"text-align: center;\"><span style=\"color: #000000;\">if single statement execution example<\/span><\/p>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here, there is a variable myData, which is initialized to a value 20. So, only one statement is coming right after the if statement. This is a case of single statement execution.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">And take a look at the expression, myData &gt; 40 is an expression that is used for the if statement. <\/span><b>&gt;<\/b><span style=\"font-weight: 400;\"> is uses a relational operator. Now here, if(myData &gt;40), if this evaluation is true, then only this printf statement will be executed. In this case, myData is 20. So, 20 &gt; 40, which is false. That&#8217;s why myData &gt; 40 statement will not be executed. So, the control reaches this point, myData++ and myData++ statement will be executed because this statement is outside the if block. So, it is always executed. Whether myData &gt; 40 expression evaluation is true or false doesn&#8217;t matter, myData++ is outside the if block, so it is always executed.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">Here, what happens is, when 20 is compared with 40, the result is zero. That&#8217;s why it will become something like this<\/span><b> if(0)<\/b><span style=\"font-weight: 400;\">. The expression result is false. That&#8217;s why this printf statement will not be executed. <\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You can even put curly braces after the if(expression)\u2014no problem. So, even for the single statement execution, you are free to put curly braces. But, since it is a single statement, we don&#8217;t usually put braces.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now, let&#8217;s take a look at the below program.<\/span><\/p>\n<pre class=\"color-5-text-contrast color5-background-color\" style=\"font-size: 12px; box-shadow: #cecece 0px 0px 0px 0px inset;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\"><span style=\"color: #ff99cc;\">int<\/span> main(<span style=\"color: #ff99cc;\">void<\/span>)\r\n\r\n{\r\n\r\n<span style=\"color: #008000;\">&nbsp;uint8_t<\/span> myData = 60;\r\n\r\n<span style=\"color: #ff99cc;\"> if<\/span>(myData &gt; 40)\r\n{\r\n<span style=\"color: #ff00ff;\">  printf<\/span>(\"value = %d\\n\", myData);\r\n  myData = 0;\r\n}\r\n<span style=\"color: #339966;\">\r\n\/*this statement is outside if block, so always execute *\/<\/span>\r\n\r\n  myData++;\r\n\r\n<span style=\"color: #ff99cc;\">  return <\/span>0;\r\n\r\n}<\/pre>\n<p class=\"\" style=\"text-align: center;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\">if multiple statement example<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here, our goal is to execute two statements. If the condition or expression is true, you must use curly braces around the if statement. So, if you are trying to execute two or more statements if the condition is true, then you have to use the curly braces; you have to remember that.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Here, myData = 60, so 60&gt;40 which is true. It looks something like if(1). So hence, there are two statements in the if() block that will be executed.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">After that, control comes out of the body of the if statement, and then it will execute the myData++ statement, and after that, return 0 will be executed. <\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In Figure 4, you can see the conditional statements. Those statements are called conditional statements because its execution depends upon evaluation of an expression (myData &gt; 40). <\/span><\/p>\n<figure id=\"attachment_10541\" aria-describedby=\"caption-attachment-10541\" style=\"width: 653px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-10541 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/07\/Figure-6-14-1024x550.png\" alt=\"Figure 6. Example\" width=\"653\" height=\"351\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-6-14-1024x550.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-6-14-300x161.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-6-14-768x412.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-6-14-600x322.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-6-14-1536x824.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-6-14-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-6-14-500x268.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-6-14-200x107.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-6-14-400x215.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-6-14-800x429.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-6-14-1200x644.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-6-14.png 1891w\" sizes=\"(max-width: 653px) 100vw, 653px\" \/><figcaption id=\"caption-attachment-10541\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 4. Example<\/span><\/figcaption><\/figure>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 22px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"text-decoration: underline; color: #000080;\"><strong>Semicolon and &#8216;if&#8217; Statement:<\/strong><\/span><\/p>\n<figure id=\"attachment_10542\" aria-describedby=\"caption-attachment-10542\" style=\"width: 651px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-10542 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/07\/Figure-7-12-1024x553.png\" alt=\"Figure 7. Example\" width=\"651\" height=\"351\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-7-12-1024x553.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-7-12-300x162.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-7-12-768x415.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-7-12-600x324.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-7-12-1536x829.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-7-12-120x65.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-7-12-500x270.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-7-12-200x108.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-7-12-400x216.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-7-12-800x432.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-7-12-1200x648.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-7-12.png 1869w\" sizes=\"(max-width: 651px) 100vw, 651px\" \/><figcaption id=\"caption-attachment-10542\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 5. Example<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<ul class=\"\" style=\"font-size: 17px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">\n<li><span style=\"color: #000000;\">Avoid adding a semicolon immediately after the <code>if<\/code> statement, as it changes the logic.<\/span><\/li>\n<li><span style=\"color: #000000;\">A semicolon by itself represents a no-operation (NOP), so the subsequent code is not part of the conditional block.<\/span><\/li>\n<li><span style=\"color: #000000;\">Be cautious not to accidentally add a semicolon after an <code>if<\/code> statement.<\/span><\/li>\n<\/ul>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">You observe the program, there is no semicolon for the if statement. So, if you give a semicolon, then the meaning of the execution of the statement completely changes. And please note that the compiler will not issue any syntax error for this.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400;\"><span style=\"color: #000000;\">Now, I will tell you the meaning of giving a semicolon. But logically, it is incorrect here, so the compiler may be issuing some warning but will not generate any error.&nbsp;<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">I give a semicolon here. Let&#8217;s analyze how exactly the program behaves.<\/span><\/p>\n<figure id=\"attachment_10543\" aria-describedby=\"caption-attachment-10543\" style=\"width: 651px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-10543 \" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/07\/Figure-8-11-1024x501.png\" alt=\"Figure 8. Example\" width=\"651\" height=\"319\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-8-11-1024x501.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-8-11-300x147.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-8-11-768x376.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-8-11-600x294.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-8-11-1536x751.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-8-11-120x59.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-8-11-500x245.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-8-11-200x98.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-8-11-400x196.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-8-11-800x391.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-8-11-1200x587.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-8-11.png 1903w\" sizes=\"(max-width: 651px) 100vw, 651px\" \/><figcaption id=\"caption-attachment-10543\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 6. Example<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now, this code is equivalent to this code. Here observe that I have given a semicolon. Now, this is an equivalent code. I have just used some curly braces to explain properly. This statement, you can visualize something like this, if(myData&gt;40), then execute a semicolon.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">In &#8216;C&#8217;, a semicolon (;) by itself or an empty block( {}) (empty block means,&nbsp; pair of curly braces), which is no operation(NOP). If (myData&gt;40) condition is true, the semicolon will be executed. That means NOP. And rest of the statements are now outside the if body. That&#8217;s why the meaning of your logic completely changes here. So, now these are not conditional statements.<\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">So, it doesn&#8217;t matter whether this expression is true or false; these statements will always be executed. That&#8217;s why giving a semicolon completely changes the logic of your program. So, you have to be careful with a semicolon. So, don&#8217;t give a semicolon with an if statement unless you are very sure about what you are trying to do. So, never give a semicolon with an if statement.<\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<figure id=\"attachment_10544\" aria-describedby=\"caption-attachment-10544\" style=\"width: 543px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-10544\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/07\/Figure-9-9-1024x545.png\" alt=\"if statement in C\" width=\"543\" height=\"289\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-9-9-1024x545.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-9-9-300x160.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-9-9-768x409.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-9-9-600x319.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-9-9-1536x817.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-9-9-120x64.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-9-9-500x266.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-9-9-200x106.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-9-9-400x213.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-9-9-800x426.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-9-9-1200x639.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-9-9.png 1881w\" sizes=\"(max-width: 543px) 100vw, 543px\" \/><figcaption id=\"caption-attachment-10544\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 7. Example<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">The relation operator, such as equal to(==), greater than(&gt;), lesser than(&lt;), these relation operators and logical operators are frequently used. I mean, of course, the bitwise operations are frequently used as the basis of conditions or expression in<\/span><b> if <\/b><span style=\"font-weight: 400;\">and <\/span><b>if\/else<\/b><span style=\"font-weight: 400;\"> conditional statements to direct the program flow. Most of the time, if(expression), this expression is made up of relation operators, or logical operators,&nbsp; or bitwise operators. And we&#8217;ll see as we make a progress when we take up examples.<\/span><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Now let\u2019s take another example.<\/span><\/p>\n<figure id=\"attachment_10545\" aria-describedby=\"caption-attachment-10545\" style=\"width: 576px\" class=\"wp-caption aligncenter\"><img loading=\"lazy\" decoding=\"async\" class=\"wp-image-10545\" src=\"http:\/\/fastbitlab.com\/wp-content\/uploads\/2022\/07\/Figure-10-6-1024x427.png\" alt=\"if statement in C\" width=\"576\" height=\"240\" srcset=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-10-6-1024x427.png 1024w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-10-6-300x125.png 300w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-10-6-768x320.png 768w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-10-6-600x250.png 600w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-10-6-1536x641.png 1536w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-10-6-120x50.png 120w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-10-6-500x209.png 500w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-10-6-200x83.png 200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-10-6-400x167.png 400w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-10-6-800x334.png 800w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-10-6-1200x500.png 1200w, https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-10-6.png 1839w\" sizes=\"(max-width: 576px) 100vw, 576px\" \/><figcaption id=\"caption-attachment-10545\" class=\"wp-caption-text\"><span style=\"color: #000000;\">Figure 8. Example<\/span><\/figcaption><\/figure>\n<p class=\"\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"color: #000000;\"><span style=\"font-weight: 400;\">There is a program, and the expression here is nothing but a variable itself. This is also a valid expression. First <\/span><b>isButtonPressed<\/b><span style=\"font-weight: 400;\">, this variable is initialized to 0. So, now this condition if(isButtonPressed) becomes if(0), which is false.<\/span><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-family: 'Roboto Slab'; font-weight: 400; font-size: 17px; line-height: 30px;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><span style=\"font-weight: 400; color: #000000;\">Whenever the button is pressed, the interrupt service routine associated with a button is executed, and inside the ISR code, the variable is set to 1. So, when the isButtonPressed variable is set to 1 and when this if statement is again executed, then it becomes if(1), and that is true. And at that time, statements in the if block will be executed. So, the takeaway from this slide is you can even use a variable as an expression.<\/span><\/p>\n<p data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\">&nbsp;<\/p>\n<p class=\"\" style=\"font-size: 18px; line-height: 30px; font-family: 'Roboto Slab'; font-weight: 400;\" data-font-family=\"Roboto Slab\" data-font-weight=\"400\" data-font-style=\"\"><strong><span style=\"color: #993366;\">Get the microcontroller Embedded C Programming Full course <span style=\"color: #0000ff;\"><a style=\"color: #0000ff;\" href=\"https:\/\/www.udemy.com\/course\/microcontroller-embedded-c-programming\/\">Here<\/a><\/span><\/span><\/strong><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 20px; line-height: 25px;\"><span style=\"color: #000080;\"><b>FastBit Embedded Brain Academy Courses<\/b><\/span><\/p>\n<p class=\"\" style=\"border-width: 0px; font-size: 17px;\"><span style=\"color: #000000;\">C<span style=\"font-weight: 400;\"><span style=\"color: #000000;\">lick here:<\/span>&nbsp;<\/span><\/span><span style=\"color: #0000ff;\"><a style=\"color: #0000ff; text-decoration: underline;\" href=\"http:\/\/fastbitlab.com\/course1\" target=\"_blank\" rel=\"noopener\"><span style=\"font-weight: 400;\">https:\/\/fastbitlab.com\/course1<\/span><\/a><\/span><\/p>\n<p class=\"\">&nbsp;<\/p>\n<\/div>\n<\/div>\n<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>&nbsp; &#8216;if&#8217; statement &nbsp; &nbsp; Decision making statements in \u2018C\u2019 When you are going to write some program, it will always be necessary that you will have to put some code which has to be executed only when a specific condition is satisfied. Your program has to take decision based on internal\/external events or conditions. [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":10536,"comment_status":"closed","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"ocean_post_layout":"","ocean_both_sidebars_style":"","ocean_both_sidebars_content_width":0,"ocean_both_sidebars_sidebars_width":0,"ocean_sidebar":"0","ocean_second_sidebar":"0","ocean_disable_margins":"enable","ocean_add_body_class":"","ocean_shortcode_before_top_bar":"","ocean_shortcode_after_top_bar":"","ocean_shortcode_before_header":"","ocean_shortcode_after_header":"","ocean_has_shortcode":"","ocean_shortcode_after_title":"","ocean_shortcode_before_footer_widgets":"","ocean_shortcode_after_footer_widgets":"","ocean_shortcode_before_footer_bottom":"","ocean_shortcode_after_footer_bottom":"","ocean_display_top_bar":"default","ocean_display_header":"default","ocean_header_style":"","ocean_center_header_left_menu":"0","ocean_custom_header_template":"0","ocean_custom_logo":0,"ocean_custom_retina_logo":0,"ocean_custom_logo_max_width":0,"ocean_custom_logo_tablet_max_width":0,"ocean_custom_logo_mobile_max_width":0,"ocean_custom_logo_max_height":0,"ocean_custom_logo_tablet_max_height":0,"ocean_custom_logo_mobile_max_height":0,"ocean_header_custom_menu":"0","ocean_menu_typo_font_family":"0","ocean_menu_typo_font_subset":"","ocean_menu_typo_font_size":0,"ocean_menu_typo_font_size_tablet":0,"ocean_menu_typo_font_size_mobile":0,"ocean_menu_typo_font_size_unit":"px","ocean_menu_typo_font_weight":"","ocean_menu_typo_font_weight_tablet":"","ocean_menu_typo_font_weight_mobile":"","ocean_menu_typo_transform":"","ocean_menu_typo_transform_tablet":"","ocean_menu_typo_transform_mobile":"","ocean_menu_typo_line_height":0,"ocean_menu_typo_line_height_tablet":0,"ocean_menu_typo_line_height_mobile":0,"ocean_menu_typo_line_height_unit":"","ocean_menu_typo_spacing":0,"ocean_menu_typo_spacing_tablet":0,"ocean_menu_typo_spacing_mobile":0,"ocean_menu_typo_spacing_unit":"","ocean_menu_link_color":"","ocean_menu_link_color_hover":"","ocean_menu_link_color_active":"","ocean_menu_link_background":"","ocean_menu_link_hover_background":"","ocean_menu_link_active_background":"","ocean_menu_social_links_bg":"","ocean_menu_social_hover_links_bg":"","ocean_menu_social_links_color":"","ocean_menu_social_hover_links_color":"","ocean_disable_title":"default","ocean_disable_heading":"default","ocean_post_title":"","ocean_post_subheading":"","ocean_post_title_style":"","ocean_post_title_background_color":"","ocean_post_title_background":0,"ocean_post_title_bg_image_position":"","ocean_post_title_bg_image_attachment":"","ocean_post_title_bg_image_repeat":"","ocean_post_title_bg_image_size":"","ocean_post_title_height":0,"ocean_post_title_bg_overlay":0.5,"ocean_post_title_bg_overlay_color":"","ocean_disable_breadcrumbs":"default","ocean_breadcrumbs_color":"","ocean_breadcrumbs_separator_color":"","ocean_breadcrumbs_links_color":"","ocean_breadcrumbs_links_hover_color":"","ocean_display_footer_widgets":"default","ocean_display_footer_bottom":"default","ocean_custom_footer_template":"0","ocean_post_oembed":"","ocean_post_self_hosted_media":"","ocean_post_video_embed":"","ocean_link_format":"","ocean_link_format_target":"self","ocean_quote_format":"","ocean_quote_format_link":"post","ocean_gallery_link_images":"off","ocean_gallery_id":[],"footnotes":""},"categories":[8],"tags":[16],"class_list":["post-10533","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-blog","tag-microcontroller-embedded-c-programming","entry","has-media"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.3 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>if statement in C - Syntax, flowchart, and Examples<\/title>\n<meta name=\"description\" content=\"if statement in C Programming -&gt; if Statement, if-else Statement, if-else-if ladder, Conditional Operators,\u00a0Switch\/case Statement. there are 5 Decision making statements in \u2018C\u2019.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"if statement in C - Syntax, flowchart, and Examples\" \/>\n<meta property=\"og:description\" content=\"if statement in C Programming -&gt; if Statement, if-else Statement, if-else-if ladder, Conditional Operators,\u00a0Switch\/case Statement. there are 5 Decision making statements in \u2018C\u2019.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/\" \/>\n<meta property=\"og:site_name\" content=\"FastBit EBA\" \/>\n<meta property=\"article:publisher\" content=\"https:\/\/www.facebook.com\/fastbiteba\/\" \/>\n<meta property=\"article:published_time\" content=\"2022-07-21T10:24:39+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2024-10-08T11:45:32+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28.png\" \/>\n\t<meta property=\"og:image:width\" content=\"1619\" \/>\n\t<meta property=\"og:image:height\" content=\"867\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\n<meta name=\"author\" content=\"FastBitLab\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:creator\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:site\" content=\"@fastbiteba\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"FastBitLab\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"8 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/if-statement-in-c\\\/#article\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/if-statement-in-c\\\/\"},\"author\":{\"name\":\"FastBitLab\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\"},\"headline\":\"Microcontroller Embedded C Programming Lecture 83| &#8216;if&#8217; statement\",\"datePublished\":\"2022-07-21T10:24:39+00:00\",\"dateModified\":\"2024-10-08T11:45:32+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/if-statement-in-c\\\/\"},\"wordCount\":1496,\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/if-statement-in-c\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/Figure-1-28.png\",\"keywords\":[\"Microcontroller Embedded C programming Lectures\"],\"articleSection\":[\"Blog\"],\"inLanguage\":\"en-US\"},{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/if-statement-in-c\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/if-statement-in-c\\\/\",\"name\":\"if statement in C - Syntax, flowchart, and Examples\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/if-statement-in-c\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/if-statement-in-c\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/Figure-1-28.png\",\"datePublished\":\"2022-07-21T10:24:39+00:00\",\"dateModified\":\"2024-10-08T11:45:32+00:00\",\"description\":\"if statement in C Programming -> if Statement, if-else Statement, if-else-if ladder, Conditional Operators,\u00a0Switch\\\/case Statement. there are 5 Decision making statements in \u2018C\u2019.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/if-statement-in-c\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/if-statement-in-c\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/if-statement-in-c\\\/#primaryimage\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/Figure-1-28.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2022\\\/07\\\/Figure-1-28.png\",\"width\":1619,\"height\":867,\"caption\":\"Figure 1. Decision making in \u2018C\u2019\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/if-statement-in-c\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"Microcontroller Embedded C Programming Lecture 83| &#8216;if&#8217; statement\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#website\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"name\":\"FastBit EBA\",\"description\":\"Your Online Academy of Embedded Systems\",\"publisher\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#organization\",\"name\":\"FastBit EBA\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\",\"url\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"contentUrl\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/wp-content\\\/uploads\\\/2026\\\/04\\\/logo-EzNrEnyr.png\",\"width\":640,\"height\":640,\"caption\":\"FastBit EBA\"},\"image\":{\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/logo\\\/image\\\/\"},\"sameAs\":[\"https:\\\/\\\/www.facebook.com\\\/fastbiteba\\\/\",\"https:\\\/\\\/x.com\\\/fastbiteba\",\"https:\\\/\\\/www.linkedin.com\\\/in\\\/fastbit-embedded-brain-academy-b3167b124\\\/\",\"https:\\\/\\\/www.youtube.com\\\/channel\\\/UCa1REBV9hyrzGp2mjJCagBg\"]},{\"@type\":\"Person\",\"@id\":\"https:\\\/\\\/fastbitlab.com\\\/blog\\\/#\\\/schema\\\/person\\\/e32b38e733a0d76ffa7e6bc998652e5d\",\"name\":\"FastBitLab\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"url\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"contentUrl\":\"https:\\\/\\\/secure.gravatar.com\\\/avatar\\\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g\",\"caption\":\"FastBitLab\"},\"description\":\"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries.\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"if statement in C - Syntax, flowchart, and Examples","description":"if statement in C Programming -> if Statement, if-else Statement, if-else-if ladder, Conditional Operators,\u00a0Switch\/case Statement. there are 5 Decision making statements in \u2018C\u2019.","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:\/\/fastbitlab.com\/blog\/if-statement-in-c\/","og_locale":"en_US","og_type":"article","og_title":"if statement in C - Syntax, flowchart, and Examples","og_description":"if statement in C Programming -> if Statement, if-else Statement, if-else-if ladder, Conditional Operators,\u00a0Switch\/case Statement. there are 5 Decision making statements in \u2018C\u2019.","og_url":"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/","og_site_name":"FastBit EBA","article_publisher":"https:\/\/www.facebook.com\/fastbiteba\/","article_published_time":"2022-07-21T10:24:39+00:00","article_modified_time":"2024-10-08T11:45:32+00:00","og_image":[{"width":1619,"height":867,"url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28.png","type":"image\/png"}],"author":"FastBitLab","twitter_card":"summary_large_image","twitter_creator":"@fastbiteba","twitter_site":"@fastbiteba","twitter_misc":{"Written by":"FastBitLab","Est. reading time":"8 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/#article","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/"},"author":{"name":"FastBitLab","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d"},"headline":"Microcontroller Embedded C Programming Lecture 83| &#8216;if&#8217; statement","datePublished":"2022-07-21T10:24:39+00:00","dateModified":"2024-10-08T11:45:32+00:00","mainEntityOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/"},"wordCount":1496,"publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28.png","keywords":["Microcontroller Embedded C programming Lectures"],"articleSection":["Blog"],"inLanguage":"en-US"},{"@type":"WebPage","@id":"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/","url":"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/","name":"if statement in C - Syntax, flowchart, and Examples","isPartOf":{"@id":"https:\/\/fastbitlab.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/#primaryimage"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/#primaryimage"},"thumbnailUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28.png","datePublished":"2022-07-21T10:24:39+00:00","dateModified":"2024-10-08T11:45:32+00:00","description":"if statement in C Programming -> if Statement, if-else Statement, if-else-if ladder, Conditional Operators,\u00a0Switch\/case Statement. there are 5 Decision making statements in \u2018C\u2019.","breadcrumb":{"@id":"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/#primaryimage","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2022\/07\/Figure-1-28.png","width":1619,"height":867,"caption":"Figure 1. Decision making in \u2018C\u2019"},{"@type":"BreadcrumbList","@id":"https:\/\/fastbitlab.com\/blog\/if-statement-in-c\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/fastbitlab.com\/blog\/"},{"@type":"ListItem","position":2,"name":"Microcontroller Embedded C Programming Lecture 83| &#8216;if&#8217; statement"}]},{"@type":"WebSite","@id":"https:\/\/fastbitlab.com\/blog\/#website","url":"https:\/\/fastbitlab.com\/blog\/","name":"FastBit EBA","description":"Your Online Academy of Embedded Systems","publisher":{"@id":"https:\/\/fastbitlab.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/fastbitlab.com\/blog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/fastbitlab.com\/blog\/#organization","name":"FastBit EBA","url":"https:\/\/fastbitlab.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","contentUrl":"https:\/\/fastbitlab.com\/blog\/wp-content\/uploads\/2026\/04\/logo-EzNrEnyr.png","width":640,"height":640,"caption":"FastBit EBA"},"image":{"@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/logo\/image\/"},"sameAs":["https:\/\/www.facebook.com\/fastbiteba\/","https:\/\/x.com\/fastbiteba","https:\/\/www.linkedin.com\/in\/fastbit-embedded-brain-academy-b3167b124\/","https:\/\/www.youtube.com\/channel\/UCa1REBV9hyrzGp2mjJCagBg"]},{"@type":"Person","@id":"https:\/\/fastbitlab.com\/blog\/#\/schema\/person\/e32b38e733a0d76ffa7e6bc998652e5d","name":"FastBitLab","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/9230d0f9bdef28b63a01e7ca274ee7b2e8ed9abe932ee564af8809caaf52a0c8?s=96&d=mm&r=g","caption":"FastBitLab"},"description":"The FastBit Embedded Brain Academy uses the power of internet to bring the online courses related to the field of embedded system programming, Real time operating system, Embedded Linux systems, etc at your finger tip with very low cost. Backed with strong experience of industry, we have produced lots of courses with the customer enrolment over 3000+ across 100+ countries."}]}},"_links":{"self":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/10533","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/comments?post=10533"}],"version-history":[{"count":6,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/10533\/revisions"}],"predecessor-version":[{"id":16981,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/posts\/10533\/revisions\/16981"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media\/10536"}],"wp:attachment":[{"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/media?parent=10533"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/categories?post=10533"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/fastbitlab.com\/blog\/wp-json\/wp\/v2\/tags?post=10533"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}