Control flow statements always control the execution flow of the program.
i.e
1. Selection statement :- Selection statements are also called as decision making statements
Syntax to if: If (condition) { Statement 1; Statement 2; Statement 3; ---------------------- ----------------------- }
Condition part will terminals with next semicolon(;) Else :- It is a keyword, by using this keyword, we can create alternate block for if condition.
|
|
|
Generally when we are working with constant expressions, we will get warning message from compiler i.e condition is always false or true.
Printf(“NIT”); Printf(“welcome”); If(15!=5!=0) // if(0!=5!=0) // if(1!=0) { Printf(“A”); Printf(“B”); } Printf(“c”); } o/p:-NIT welcome ABC “Every non Zero is true”
{ Printf(“welcome”); Printf(“NIT”); If(!5) Printf(“A”); Printf(“B”); Printf(“c”); O/P: WelcomeNITBC. When we are constructing multiple statements without using body then first statement only will consider within the “if”, because scope will be terminated with next semicolon.
{ Printf(“A”); If(5>2 && 8<5) // if(1 && 0) { Printf(“B”); Printf(“c”); } Else { Printf(“welcome”); Printf(“Hello”); } Printf(“D”); } o/p: a welcome Hello
Printf(“welcome”); If(1<2!=0 && 1=5>2) // if(1!=0 && 1==1) { Printf(“A”); Printf(“B”); } Else { Printf(“x”); Printf(“y”); } Printf(“NIT”); } o/p:- Welcome AB NIT.
{ Printf(“A”); If(8!=8>2 or 4!=1<4) { Printf(“B”); Printf(“C”); } Else Printf(“NIT”); Printf(“Y”); Printf(“Z”); } o/p: ABCYZ. When the body is not specified for else part then automatically scope will terminated with next statement only. Ie. Under the else part, first statement will place
Printf(“Hello”); If(15!=2>5) Printf(“A”); Printf(“B”); on necessary because else should start at the else immediate ending of if statement. If is not { having the body. Printf(“X”); Printf(“Y”); } } o/p: Error misplaced error when we are using the else part, it should start immediately of if scope only i.e where the scope of the if is terminated there itself. Else part must be started.
You liked the article?
Like: 0
Vote for difficulty
Current difficulty (Avg): Medium
TekSlate is the best online training provider in delivering world-class IT skills to individuals and corporates from all parts of the globe. We are proven experts in accumulating every need of an IT skills upgrade aspirant and have delivered excellent services. We aim to bring you all the essentials to learn and master new technologies in the market with our articles, blogs, and videos. Build your career success with us, enhancing most in-demand skills in the market.