<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Talk Binary &#187; if</title>
	<atom:link href="http://talkbinary.com/tag/if/feed/" rel="self" type="application/rss+xml" />
	<link>http://talkbinary.com</link>
	<description>Programming Resources, Technology, Computers</description>
	<lastBuildDate>Wed, 15 Feb 2012 16:01:31 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.3.2</generator>
		<item>
		<title>Basic Control Flow Continued</title>
		<link>http://talkbinary.com/programming/c/basic-control-flow-continued/</link>
		<comments>http://talkbinary.com/programming/c/basic-control-flow-continued/#comments</comments>
		<pubDate>Thu, 26 Jun 2008 01:14:38 +0000</pubDate>
		<dc:creator>Diego</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[bool]]></category>
		<category><![CDATA[else]]></category>
		<category><![CDATA[if]]></category>
		<category><![CDATA[if-else]]></category>

		<guid isPermaLink="false">http://talkbinary.com/?p=135</guid>
		<description><![CDATA[By this time you should be familiar with the basics behind If and Else if statements. Below you&#8217;ll see more examples and more ways to use Control Flow in your programming. 1. You&#8217;ll learn more advanced ways of manipulating control flow in your program. 2. You&#8217;ll also learn how to declare and initialize boolean variables.<a class="moretag" href="http://talkbinary.com/programming/c/basic-control-flow-continued/">&#160;&#160;Full Article&#8230;</a>
]]></description>
			<content:encoded><![CDATA[<p>By this time you should be familiar with the basics behind If and Else if statements. Below you&#8217;ll see more examples and more ways to use Control Flow in your programming.<br/><br />
1. You&#8217;ll learn more advanced ways of manipulating control flow in your program.<br />
2. You&#8217;ll also learn how to declare and initialize boolean variables.<br />
<br/></p>
<h3 id="section-1">Boolean Variables</h3>
<p>Boolean variables are another built in data type in C++ that allow you to assign it either a TRUE, or FALSE value. What is this useful for? Let&#8217;s see below. (Declaring and assigning a value to a bool value is really similar to int, double, and strings).<br />
<br/><span id="more-135"></span></p>
<pre lang="c++">
bool success = FALSE;
int age;
cin >> age;

//If user entered a value between 0 and 120 we can assume they entered a correct value. If not, SUCCESS remains FALSE.
if ( age < 120 &#038;&#038; age > 0 ) success = TRUE; 

//If user either put a negative number or above 120 then we "assume" they lied about their age and terminate the program.
if ( !success ) return 0; 

cout << "Based on your age we can determine..." << endl;
//Do more stuff
</pre>
<p>In other words, if the user did satisfy our age requirement, we can continue with our program.<br/><br/></p>
<h3 id="section-2">Explanation:</h3>
<p>You may have also noticed I used the following:</p>
<pre lang="c++">if ( !success )</pre>
<p>This simply means if success is NOT TRUE (In other words, FALSE), the following return would execute thus terminating the program. <br/><br/></p>
<pre lang="c++">if ( success ) //Simple means, if SUCCESS is TRUE</pre>
<p><br/></p>
<p>If you also noticed, I included the following:</p>
<pre lang="c++">if ( age < 120 &#038;&#038; age > 0 )</pre>
<p></br>In other words, you may have more than one condition in your if statements. <br/><br />
You may use <strong>and</strong> or <strong>&#038;&#038;</strong> as well as <strong>or</strong> or <strong>||</strong>. <br/><br />
When you concatenate conditions with the <strong>AND</strong> operator it means in order for the if statement to execute, ALL conditions must be true. For <strong>OR</strong> only one condition must be met.<br />
<br/></p>
<h3 id="section-3">More advanced examples</h3>
<p>Try figuring out how this following code would work. Try it yourself. It's the best way to learn! Fill in the cases of course with code of your desire.<br />
<br/></p>
<pre lang="c++">
bool success = false; //Remember to always initialize bool variables
int num1, num2, num3;

//Some lines that modify the previous variables.

if ( success ) {
	if ( (num1 <= num2) || num3 > 100 ) {
	     //Case 1
	}
	else if ( num1 == num3 ) {
	     //Case 2
	}
	else {
	     //Case 3
	}
}
else { return 0; } 

//Since success, keep doing other code.
</pre>
<p><br/></p>
<h3 id="section-4">What now?</h3>
<p>Keep practicing! If you have any more questions feel free to ask below or join the forums and ask the community!</p>
]]></content:encoded>
			<wfw:commentRss>http://talkbinary.com/programming/c/basic-control-flow-continued/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>Basic Control Flow</title>
		<link>http://talkbinary.com/programming/c/basic-control-flow/</link>
		<comments>http://talkbinary.com/programming/c/basic-control-flow/#comments</comments>
		<pubDate>Wed, 25 Jun 2008 06:55:10 +0000</pubDate>
		<dc:creator>Diego</dc:creator>
				<category><![CDATA[C++]]></category>
		<category><![CDATA[control flow]]></category>
		<category><![CDATA[else]]></category>
		<category><![CDATA[if]]></category>

		<guid isPermaLink="false">http://talkbinary.com/?p=134</guid>
		<description><![CDATA[In the following tutorial, you&#8217;ll learn how to use if, and if-else statements. They are useful for deciding on what lines of code to execute based on values of previous variables in your program. The If Statement An example is as follows int x; if ( condition ) x = 50; //If condition returns TRUE,<a class="moretag" href="http://talkbinary.com/programming/c/basic-control-flow/">&#160;&#160;Full Article&#8230;</a>
]]></description>
			<content:encoded><![CDATA[<p>In the following tutorial, you&#8217;ll learn how to use if, and if-else statements. They are useful for deciding on what lines of code to execute based on values of previous variables in your program.</p>
<p><br/></p>
<h3 id="section-1">The If Statement</h3>
<p>An example is as follows</p>
<pre lang="c++">
int x;
if ( condition ) x = 50; //If condition returns TRUE, assign 50 to X.
</pre>
<p>In other words, if the condition you provide returns a boolean value ( is a value that returns either TRUE or FALSE ) TRUE, then the following statements enclosed with {}&#8217;s are executed (no need if only one statement follows the if statement). <span id="more-134"></span><br />
<br/><br />
You may use the following operands in your conditions&#8230;<br />
== &#8211; EQUAL TO<br />
!=  &#8211; NOT EQUAL TO<br />
<   - LESS THAN<br />
<= - LESS THAN OR EQUAL TO<br />
>   &#8211;  GREATER THAN<br />
>= &#8211;  GREATER THAN OR EQUAL TO<br />
<br/>Here is an actual example.</p>
<pre lang="c++">
int number;
cin >> number;
if ( number == 50 ) {
cout << "Congratulations! You picked the right number!" << endl;
}
</pre>
<p>In other words, if the user typed in 50, the if statement will be true and print the following line to the screen.<br />
<br/></p>
<h3 id="section-2">The If and Else</h3>
<p>Let's say we want to output something if it was false.</p>
<pre lang="c++">
int number;
cin >> number;
if ( number == 50 ) {
cout << "Congratulations! You picked the right number!" << endl;
}
else {
cout << "Sorry! You were wrong!" << endl; //Second Statement
}</pre>
<p>Then, if the user didn't type in 50, it would output the second statement.<br />
<br/></p>
<h3 id="section-3">The If, Else-If, and Else</h3>
<p>What if we wanted to check other conditions as well? </p>
<pre lang="c++">
int number;
cin >> number;
if ( number == 50 ) {
cout << "Congratulations! You picked the right number!" << endl;
}
else if ( number > 50 ) {
cout << "Sorry! You were over!" << endl; //New Statement
}
else {
cout << "Sorry! You were way off!" << endl;
}</pre>
<p>In other words, this one has a different output if the user entered a number larger than 50! If the user didn't choose 50, or a number larger than fifty, then the last else statement would be executed.<br />
<br/><br />
Keep in mind that you may add multiple else if statements! Just remember to have good coding style in order for any future reader to understand what statements pertain to what if condition. The way my code is written is a really good way of styling your code as its easy to read and follow!<br />
<br/></p>
<h3 id="section-4">So what now?</h3>
<p>If you have trouble don't be afraid to post below any questions, comments, or concerns!<br />
<br/>In the next tutorial expect to learn how to use If, Else If, and Else statements in more detail!</p>
]]></content:encoded>
			<wfw:commentRss>http://talkbinary.com/programming/c/basic-control-flow/feed/</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>

<!-- Performance optimized by W3 Total Cache. Learn more: http://www.w3-edge.com/wordpress-plugins/

Page Caching using disk: enhanced

Served from: talkbinary.com @ 2012-05-23 22:19:29 -->
