A<?xml version="1.0"?>
<feed xmlns="http://www.w3.org/2005/Atom" xml:lang="ru">
		<id>http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C_Tutorial%2FStatement%2FIf_statement</id>
		<title>C Tutorial/Statement/If statement - История изменений</title>
		<link rel="self" type="application/atom+xml" href="http://www.cppe.ru/index.php?action=history&amp;feed=atom&amp;title=C_Tutorial%2FStatement%2FIf_statement"/>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C_Tutorial/Statement/If_statement&amp;action=history"/>
		<updated>2026-04-19T06:22:46Z</updated>
		<subtitle>История изменений этой страницы в вики</subtitle>
		<generator>MediaWiki 1.30.0</generator>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C_Tutorial/Statement/If_statement&amp;diff=3814&amp;oldid=prev</id>
		<title> в 14:21, 25 мая 2010</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C_Tutorial/Statement/If_statement&amp;diff=3814&amp;oldid=prev"/>
				<updated>2010-05-25T14:21:19Z</updated>
		
		<summary type="html">&lt;p&gt;&lt;/p&gt;
&lt;table class=&quot;diff diff-contentalign-left&quot; data-mw=&quot;interface&quot;&gt;
				&lt;tr style=&quot;vertical-align: top;&quot; lang=&quot;ru&quot;&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;← Предыдущая&lt;/td&gt;
				&lt;td colspan=&quot;1&quot; style=&quot;background-color: white; color:black; text-align: center;&quot;&gt;Версия 14:21, 25 мая 2010&lt;/td&gt;
				&lt;/tr&gt;&lt;tr&gt;&lt;td colspan=&quot;2&quot; style=&quot;text-align: center;&quot; lang=&quot;ru&quot;&gt;&lt;div class=&quot;mw-diff-empty&quot;&gt;(нет различий)&lt;/div&gt;
&lt;/td&gt;&lt;/tr&gt;&lt;/table&gt;</summary>
			</entry>

	<entry>
		<id>http://www.cppe.ru/index.php?title=C_Tutorial/Statement/If_statement&amp;diff=3815&amp;oldid=prev</id>
		<title>Admin: 1 версия:&amp;#32;Импорт контента...</title>
		<link rel="alternate" type="text/html" href="http://www.cppe.ru/index.php?title=C_Tutorial/Statement/If_statement&amp;diff=3815&amp;oldid=prev"/>
				<updated>2010-05-25T10:32:41Z</updated>
		
		<summary type="html">&lt;p&gt;1 версия: Импорт контента...&lt;/p&gt;
&lt;p&gt;&lt;b&gt;Новая страница&lt;/b&gt;&lt;/p&gt;&lt;div&gt;==Checking for a Range of Values==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
  int iResponse = 0;&lt;br /&gt;
  printf(&amp;quot;Enter a number from 1 to 10: &amp;quot;);&lt;br /&gt;
  scanf(&amp;quot;%d&amp;quot;, &amp;amp;iResponse);&lt;br /&gt;
  if ( iResponse &amp;lt; 1 || iResponse &amp;gt; 10 )&lt;br /&gt;
    printf(&amp;quot;\nNumber not in range\n&amp;quot;);&lt;br /&gt;
  else&lt;br /&gt;
    printf(&amp;quot;\nThank you\n&amp;quot;);&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Enter a number from 1 to 10: 2&lt;br /&gt;
      &lt;br /&gt;
      Thank you&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==if Comparisons and Their Opposites==&lt;br /&gt;
&lt;br /&gt;
if Comparison&lt;br /&gt;
else Statement Executed By This Condition&lt;br /&gt;
&amp;lt;&lt;br /&gt;
&amp;gt;=&lt;br /&gt;
==&lt;br /&gt;
!=&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;lt;=&lt;br /&gt;
&amp;lt;=&lt;br /&gt;
&amp;gt;&lt;br /&gt;
&amp;gt;=&lt;br /&gt;
&amp;lt;&lt;br /&gt;
!=&lt;br /&gt;
==&lt;br /&gt;
&lt;br /&gt;
==if statement==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;To conditionally execute statements, you can use the if or the if...else statement.&amp;lt;/p&amp;gt;&lt;br /&gt;
&amp;lt;p&amp;gt;The general form of the if statement is&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;if(expr) {&lt;br /&gt;
    s1 ;&lt;br /&gt;
    s2 ;&lt;br /&gt;
    ....&lt;br /&gt;
  }&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==if statement: compare the value from user input==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
  int number = 0;&lt;br /&gt;
  printf(&amp;quot;\nEnter an integer between 1 and 10: &amp;quot;);&lt;br /&gt;
  scanf(&amp;quot;%d&amp;quot;,&amp;amp;number);&lt;br /&gt;
  if (number &amp;gt; 5)&lt;br /&gt;
    printf(&amp;quot;You entered %d which is greater than 5\n&amp;quot;, number);&lt;br /&gt;
  if (number &amp;lt; 6)&lt;br /&gt;
    printf(&amp;quot;You entered %d which is less than 6\n&amp;quot;, number);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Enter an integer between 1 and 10: 5&lt;br /&gt;
     You entered 5 which is less than 6&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==if statement with two else statements==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;stdlib.h&amp;gt;&lt;br /&gt;
 &lt;br /&gt;
int main()&lt;br /&gt;
{&lt;br /&gt;
    char num[2];&lt;br /&gt;
    int number;&lt;br /&gt;
 &lt;br /&gt;
    printf(&amp;quot;Enter a number from 0 to 9:&amp;quot;);&lt;br /&gt;
    gets(num);&lt;br /&gt;
    number=atoi(num);&lt;br /&gt;
 &lt;br /&gt;
    if(number&amp;lt;5)&lt;br /&gt;
    {&lt;br /&gt;
        printf(&amp;quot;That number is less than 5!\n&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    else if(number==5)&lt;br /&gt;
    {&lt;br /&gt;
        printf(&amp;quot;You typed in 5!\n&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
    else&lt;br /&gt;
    {&lt;br /&gt;
        printf(&amp;quot;That number is more than 5!\n&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
 &lt;br /&gt;
    return(0);&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Enter a number from 0 to 9:2&lt;br /&gt;
      That number is less than 5!&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==If with else statement==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;The general format for an if-else statement is&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;if (condition)&lt;br /&gt;
   simple or compound statement  &lt;br /&gt;
else&lt;br /&gt;
   simple or compound statement.&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Operators Used in if Comparisons==&lt;br /&gt;
&lt;br /&gt;
Comparison&lt;br /&gt;
Meaning or Pronunciation&lt;br /&gt;
&amp;quot;True&amp;quot; Example&lt;br /&gt;
&amp;lt;&lt;br /&gt;
Less than&lt;br /&gt;
1 &amp;lt; 5, 8 &amp;lt; 9&lt;br /&gt;
==&lt;br /&gt;
Equal to&lt;br /&gt;
7 == 7, 1 == 1&lt;br /&gt;
&amp;gt;&lt;br /&gt;
Greater than&lt;br /&gt;
7 &amp;gt; 5, 10 &amp;gt; 0&lt;br /&gt;
&amp;lt;=&lt;br /&gt;
Less than or equal to&lt;br /&gt;
4 &amp;lt;= 5, 8 &amp;lt;= 8&lt;br /&gt;
&amp;gt;=&lt;br /&gt;
Greater than or equal to&lt;br /&gt;
6 &amp;gt;= 5, 2 &amp;gt;= 2&lt;br /&gt;
!=&lt;br /&gt;
Not equal to&lt;br /&gt;
1 != 0, 1 != 3.99&lt;br /&gt;
&lt;br /&gt;
==The if-else-if statement==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;The general format for the if-else if statement is:&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;if (condition 1)&lt;br /&gt;
   simple or compound statement  &lt;br /&gt;
else if (condition 2)&lt;br /&gt;
   simple or compound statement  &lt;br /&gt;
else if ( condition 3)&lt;br /&gt;
   simple or compound statement  &lt;br /&gt;
   .....&lt;br /&gt;
else if ( conditon n )&lt;br /&gt;
   simple or compound statement&amp;lt;/source&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==The if statement: a compound statement==&lt;br /&gt;
&lt;br /&gt;
&amp;lt;p&amp;gt;If a compound statement is used, it must be enclosed in opening and closing braces.&amp;lt;/p&amp;gt;&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include&amp;lt;stdio.h&amp;gt;&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
   int i=5, j =1;&lt;br /&gt;
   &lt;br /&gt;
    if (i &amp;gt; j){&lt;br /&gt;
        i = i + 1;&lt;br /&gt;
        printf(&amp;quot;%d&amp;quot;,i);&lt;br /&gt;
    }   &lt;br /&gt;
    else&lt;br /&gt;
        j = j +1;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;6&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==To execute only one statement, opening and closing braces are not required==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
main(){&lt;br /&gt;
  int i = 5;&lt;br /&gt;
  if(i &amp;gt; 0)&lt;br /&gt;
     printf(&amp;quot; i &amp;gt; 0. \n&amp;quot;);&lt;br /&gt;
     &lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;i &amp;gt; 0.&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use compound conditions to check for upper and lowercase letters==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
main(){&lt;br /&gt;
    char cResponse = &amp;quot;\0&amp;quot;;&lt;br /&gt;
    printf(&amp;quot;Enter the letter A: &amp;quot;);&lt;br /&gt;
    scanf(&amp;quot;%c&amp;quot;, &amp;amp;cResponse);&lt;br /&gt;
    if ( cResponse== &amp;quot;A&amp;quot; || cResponse == &amp;quot;a&amp;quot; )&lt;br /&gt;
       printf(&amp;quot;\nCorrect response\n&amp;quot;);&lt;br /&gt;
    else&lt;br /&gt;
       printf(&amp;quot;\nIncorrect response\n&amp;quot;);&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Enter the letter A: 1&lt;br /&gt;
      &lt;br /&gt;
      Incorrect response&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Use isdigit Function in if statement==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;ctype.h&amp;gt;&lt;br /&gt;
main()&lt;br /&gt;
{&lt;br /&gt;
  char cResponse = &amp;quot;\0&amp;quot;;&lt;br /&gt;
  printf(&amp;quot;\nPlease enter a letter: &amp;quot;);&lt;br /&gt;
  scanf(&amp;quot;%c&amp;quot;, &amp;amp;cResponse);&lt;br /&gt;
  if ( isdigit(cResponse)== 0 )&lt;br /&gt;
    printf(&amp;quot;\nThank you\n&amp;quot;);&lt;br /&gt;
  else&lt;br /&gt;
    printf(&amp;quot;\nYou did not enter a letter\n&amp;quot;);&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;Please enter a letter: 1&lt;br /&gt;
      &lt;br /&gt;
      You did not enter a letter&amp;lt;/pre&amp;gt;&lt;br /&gt;
&lt;br /&gt;
==Using nested ifs==&lt;br /&gt;
&lt;br /&gt;
&lt;br /&gt;
   &lt;br /&gt;
&amp;lt;source lang=&amp;quot;cpp&amp;quot;&amp;gt;#include &amp;lt;stdio.h&amp;gt;&lt;br /&gt;
#include &amp;lt;limits.h&amp;gt;&lt;br /&gt;
int main(void)&lt;br /&gt;
{&lt;br /&gt;
  long test = 0L;              &lt;br /&gt;
&lt;br /&gt;
  if( test % 2L == 0L) {&lt;br /&gt;
    printf(&amp;quot;The number %ld is even&amp;quot;, test);&lt;br /&gt;
    if ( (test/2L) % 2L == 0L)&lt;br /&gt;
    {&lt;br /&gt;
      printf(&amp;quot;\nHalf of %ld is also even&amp;quot;, test);&lt;br /&gt;
      printf(&amp;quot;\nThat&amp;quot;s interesting isn&amp;quot;t it?\n&amp;quot;);&lt;br /&gt;
    }&lt;br /&gt;
  }&lt;br /&gt;
  else&lt;br /&gt;
    printf(&amp;quot;The number %ld is odd\n&amp;quot;, test);&lt;br /&gt;
  return 0;&lt;br /&gt;
}&amp;lt;/source&amp;gt;&lt;br /&gt;
&amp;lt;pre class=codeResult&amp;gt;The number 0 is even&lt;br /&gt;
     Half of 0 is also even&lt;br /&gt;
     That&amp;quot;s interesting isn&amp;quot;t it?&amp;lt;/pre&amp;gt;&lt;/div&gt;</summary>
		<author><name>Admin</name></author>	</entry>

	</feed>