# Lesson 7: Learning the Grammatical Structure of if in #C

This is our Lesson 7: Learning the Grammatical Structure of if in #C Learning the Grammatical Structure of if in #C:. Today you will learn about the Grammatical Structure of if in #C Learning.

The if statement is one of the most significant grammatical constructs in any programming language, including C #.

One of the most significant things that computer languages can do is allow you to create general conditional expressions.

The conditional if the structure in C # is quite straightforward and practical. In any computer language, if from conditional grammatical if.

If you have used another, you can easily use it in C # as well. Conditional command structure if required
Mand is a boolean value that is either true or false.

In some programming languages, several types of data.

E can be converted to Boolean automatically, but in C # it must be directly from the Boolean data type used. For example, you can not use the int numeric data type directly, but you can compare it with another value and use the value true or false of the result.

In the previous lesson, we taught you how to define and use variables in C #.

We will also teach you how to work with conditional statements in C #. To do this, carefully read the following example code do.

``````using System;

namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
int number;
Console.WriteLine("Please enter a number between 0 and 10:");
if (number > 10)
Console.WriteLine("Hey! The number should be 10 or less!");
else
if (number < 0)
Console.WriteLine("Hey! The number should be 0 or more!");
else
Console.WriteLine("Good job!");
}
}
}``````

Grammatical Structure of if in #C

In the example code above, we have used two conditional if statements to check if the user input number is between 1 and 11.

Is it or not. The else key is also used with the if statement. The elsewhere code field runs when the condition of the if the section is not true.

If you look closely at the example code above, we use {کار characters to categorize if and else statements.

We did not. This is a rule in C #. If the written code is just a linear text, no need to use
{نیست is not for category codes.

The size of the code written to compare the value of a number in the above example seems a bit large.

The same code You can write more concisely as follows:

``````if((number > 10) || (number < 0))
Console.WriteLine("Hey! The number should be 0 or more and 10 or less!");
else
Console.WriteLine("Good job!");``````

Grammatical Structure of if in #C

We put each conditional statement in parentheses and then from the operator ǁ which means “either”, “or”.

We have to be able to enter 11 is greater than or less than 1. Another operator in this species

Items can also use the operator and means “and” which is written in &&.

Can So in the code of the second example, should we use the AND operator instead? Yes, just enter the code below Rewrite:

``````if((number <= 10) && (number >= 0))
Console.WriteLine("Good job!");
else
Console.WriteLine("Hey! The number should be 0 or more and 10 or less!");``````

In this lesson, we also introduced the “smaller than” and “larger than” operators.