What are Statements?
Statements basically instructions using some keyword. In C-Language having 5 kinds of statements
Statements basically instructions using some keyword. In C-Language having 5 kinds of statements
- IF-Else Statement
- Go To Statement
- Switch Statement
- Break Statement
- Continue Statement
-
IF-Else Statement
This statement under in decision control statements in which we control the decision of the user and we divided several parts. Each part reflects one case of decision.If else statement having one scenario know as dangling else in which having 2 if statement and one else
statement.
Syntax
Expected Output is
0 is Even Number
1 is odd Number
2 is Even Number
3 is odd Number
4 is Even Number
5 is Odd Number
6 is Even Number
7 is Odd Number
8 is Even Number
9 is Odd Number
10 is Even Number
Dangling Else Problem Example
-
Go-To Statement
Go to the statement is kind of Statement. For using GoTo statement created liable for that
and then go to statement is used. But this is not for good programming practice so it's discard
or not try to use or Avoid to use.
Syantx:
int main () { int a; label1: printf (“Enter the number greater than 10: -”); scanf (“%d”, &a); if(a>10) { printf (“Value of A is: %d”, a); } else { goto label1; } }
Switch Statement
Switch Statement is similar to if-else statement but there is one difference between If-else statement and Switch case. Switch case does not work with ranges but If-else perfectly
works with ranges. In switch case, we can pass the Integer as well as a Character value. Switch-case having one default case if in case values not matched with any case then default case
runs and shows/perform a particular task.
Syntax
switch(casenumber) { case case-number : set of instruction . . . default: set of instruction }
If the user entered value is 0 or more than 7 than its display the ‘Invalid option' message otherwise its display the Day of corresponding case. Switch case having one problem i.e. Race Around Condition in which if we not use Break statement then its start all cases after the match case
Explanation:
If user enters 1 then it's print the Sunday and also prints each case defined below of case 1 because we forgot to write the break statement after the case block so the compiler executes every case of the switch case and prints all data of the below cases
-
Break Statement
while loop body
-
CONTINUE STATEMENT
Continue Statement is the opposite of the break statement. Through this statement, we giving the instruction to the compiler to continuing the process or we can use continue statements for skipping the particular iteration of the loop.
We you have any doubt let me know :)