Notice: Undefined offset: 13927041 in /var/www/html/qa-external/qa-external-users.php on line 744
What is the role of if and if else - OnlineGDB Q&A
Hello, OnlineGDB Q&A section lets you put your programming query to fellow community users. Asking a solution for whole assignment is strictly not allowed. You may ask for help where you are stuck. Try to add as much information as possible so that fellow users can know about your problem statement easily.

What is the role of if and if else

+41 votes
asked Oct 29, 2024 by aila imran (220 points)

8 Answers

+7 votes
answered Oct 31, 2024 by Peter Minarik (101,360 points)

if and else are your typical branching instructions where you can make the code decide which path to take.

Look at the following pseudo-code for an example:

if (time == LUNCH_TIME)
    haveLunch();
else
    keepWorking();

If you're looking for some specific context, then please, provide more details.

+4 votes
answered Nov 1, 2024 by Shivansh Raj (280 points)

In C programming, the if and if-else statements are used for conditional branching, allowing the program to execute certain blocks of code based on whether a specified condition is true or false.

if Statement

The if statement checks a condition and executes a block of code if that condition evaluates to true.

if-else Statement

The if-else statement provides an alternative path of execution if the condition in the if statement is false. If the condition is true, the code inside the if block runs; if it's false, the code inside the else block runs.

+3 votes
answered Nov 14, 2024 by Poluparthi Susmitha (200 points)
If the condition is true, the code block under the if branch is executed, and the code block under the else branch is skipped.

if the condition is false, the code block under the else branch is executed, and the code block under the if branch is skipped.

if(condition){

printf("hello");

}

else{

printf("bye");

}
+2 votes
answered Nov 17, 2024 by dwivedi3011 (180 points)

If And If Else

the difference between if and if else is  very common like if we have only two possibilities then there if statement is used .And if u have more than two possibilities then we use If Else

+1 vote
answered Nov 20, 2024 by Vernon Alva (160 points)
If is basically where a there is no option display the false condition and in contrast  if else works opposite to if statement
+3 votes
answered Dec 31, 2024 by Tushar Pancheshwar (260 points)

if and else are your typical branching instructions where you can make the code decide which path to take.

Look at the following pseudo-code for an example:

if (time == LUNCH_TIME)
    haveLunch();
else
    keepWorking();
+3 votes
answered Jan 1, 2025 by DP Tripathi (200 points)
If and Else-If statements are conditional Statements

if (Condition_1)

{

Statements _1 to be execute;

}

else if(Condition_2)

{

Statements _2 to be execute;

}

When condition_1 is true then Statements _1 get executed else controller will move down and check the condition_2 and verify whether this condition is True  based on that Statements _2 get executed. if both conditions were false then neither Statements _1 nor Statements _2 get execute.
+1 vote
answered Jan 24, 2025 by kripa meenu (170 points)
if condition

code to be exicuted if codition is true

ex-  

int x=5;

if(x>10){
printf("x is greater then 10\n");

if else

int x=5;

if(x>10){
printf("xgreater than 10");

}else{

printf("x less than 10 or equal than 10");
Welcome to OnlineGDB Q&A, where you can ask questions related to programming and OnlineGDB IDE and receive answers from other members of the community.
...