Chapter 1-Module 2
Chapter 1-Module 2
Branching statements:
The statement which transfer the control from one place to another place.
1. Simple if
2. If else
3. Nested if
4. Ladder if
5. Switch
1. Goto
2. Break
3. Continue
4. Return
Syntax: if (Expression)
{
Statements;
}
If -Else statements:
The statement should execute when the condition is true,Or else part will
execute.
Syntax: if (Condition)
Statement 1;
else
Statement 2;
Example:
Syntax:
if(condition1)
if(condition2)
{ //if both 1st and 2nd condition true, it will execute the
statement 1.
Statement 1:
else // if 1st condition true but 2nd condition false, it will execute
the else part of 2nd condition.
Statement 2;
else // if 1st condition itself is false, it will execute the else part of 1 st
contion
Statement 3;
}
Example 1:
C break statement:
The break is a keyword in C which is used to bring the program control out of
the loop. The break statement is used inside loops or switch statement. The break
statement breaks the loop one by one, i.e., in the case of nested loops, it breaks
the inner loop first and then proceeds to outer loops. The break statement in C
can be used in the following two scenarios:
1. With switch case
2. With loop
Syntax:
//loop or switch case
break;
Example:
C continue statement
The continue statement in C language is used to bring the program
control to the beginning of the loop. The continue statement skips some lines of
code inside the loop and continues with the next iteration. It is mainly used for a
condition so that we can skip some code for a particular condition.
Syntax:
//loop statements
continue;
//some lines of the code which is to be skipped
C goto statement :
The goto statement is known as jump statement in C. As the name
suggests, goto is used to transfer the program control to a predefined label.
Syntax:
label:
//some part of the code;
goto label;
Return statement:
If it is a void It return nothing but If it’s a int it will return 0.