Question:
explain if else statement with syntax with example?
tanvir a
2010-05-27 10:52:11 UTC
explain if else statement with syntax with example?
Six answers:
D Bügger™
2010-05-27 20:06:36 UTC
syntax :-

if

{

//true block

}

else

{

//false block

}



explanation:-

the execution of if-else block starts from if part,first of all the condition is checked and if true then true part is executed else the false block is executed.



example:-

#include

{



int age=15;



if(age> =18)

{

printf("Adult");

}

else

{

printf("Minor");

}

}



in above example the else part would execute since age is less then 18.



other constructs for if-else are:-

if

{

//true block

}

else

if

{

//true block

}

else

{

//false block

}



refer for more details:-
?
2016-12-17 10:15:59 UTC
Explain Syntax
main_hu_naaaa
2010-05-27 10:55:45 UTC
The if-else statements enable your program to selectively execute other statements, based on some criteria. The simplest version, the if statement, is shown below. The block governed by if (delimited with '{' and '}') is executed if the expression is true, otherwise the execution continues after the last '}'.



if (expressions)

{

statement(s)

}





If you want to execute other statements when the expression is false, you use the else statement.







if (expression)

{

statement(s) executed if expression is true

}

else

{

statement(s) executed if expression is false

}



Another statement, elseif, executes statements if an earlier if expression was false and it's own expression is true; elseif is used to form chains of conditions. If expression 1 is true, the if block executes and then the program jumps to the last '}' of the else block. Expression 2 will never be evaluated. If, however, expression 1 is false, expression 2 will be evaluated and the elseif-else will work as a regular if-else as shown above.
Melissa
2010-05-27 11:53:58 UTC
The way I see it, you want something to run if ur specifications are true and if they are not you want something else to run.



If mylength > 100 Then

me.display.text="You are tall"

Else

me.display.text="You are tiny"

End If



You should declare a variable for mylength first and then also assign a value to it.



The syntax is like the guy wrote it above.
Amanda
2016-03-17 03:03:45 UTC
To clarify, in grade school divion you'd write things as X divided by Y = A remainder B e.g. 11 divided by 4 = 2 remainder 3 In programming we have / (modulo) and % (remainder) X/Y = A (2 in the above example) and X%Y = B (3 in the example)
sayan_nayas
2010-05-28 06:32:28 UTC
if i give you answer



you will be helped



else



you wil try to search google :)

-------------------------------------------------------

if(temp=="i am helped")

{

printf("yeah ! i got helped");

}



else

{

printf("no...I have to search google");

}


This content was originally posted on Y! Answers, a Q&A website that shut down in 2021.
Loading...