We know that decision making is the most important concept of all the programming languages. Condition making is the one of the important aspect of decision making.
Table of Contents
Three kind of statements
- If statements
- If-else statements
- Nested if statements
If Statements
The if statements is used to test a specific condition. If condition is true, a block of code (if-block) will be executed.
If-else sttements
The if-else statements is similar to if statement but it also provide the block of the code for the false case of the condition to be checked.
Nested if statements
Looking of statements inside another loops
If Statements in python
Syntax for if statements
if expression:
Statements
Python code for if statements
num=int(input("Number"))
if num%2==0:
print("Even")
If-else statements in c
Syntax for if-else statements
if(expression){
//code to be executed
}
#include<stdio.h>
int number;
int main()
{
printf("Enter the number:\n");
scanf("%d",&number);
if(number%2==0){
printf("This is even number");}
else printf("This is odd number");
}
In this c program we declared number as a input variable for if else statements. Use simple if else logic to print even or odd number.
Summary:
In this article we saw How to if statements id different for both languages (i.e. c and python)