HTML

Conditional Statements:
Conditional statements are the decision making statements.
These are the branching statements.
1. if:
It takes the expression in parenthesis.
If the expression is true then the block will executes.
Syntax: if( expression)
  {
statement;
}
2. if-else:
It takes the expression in parenthesis.
If the expression is true then the block will executes.
The else part contains the other statements which will executes when the if block will fail.
Syntax: if( expression)
  {
statement;
}
  else
statement
3. else-if:
If condition takes the expression in parenthesis.
If the expression is true then the block will executes.
When the if block fail the compiler enters into else if block.
if the else if expression is true then the compiler will execute the else if block
  otherwise else will execute
Syntax: if( expression)
  {
statement;
}
else if( expression)
  {
statement;
}
  else
statement
4.Switch:
The switch statement is must like a nested if statement.
These are slightly more easy to read.
Syntax: switch(expression)
{
case constant-expression1; statements;
break;
case constant-expression2; statements;
break;
case constant-expression3; statements;
break;
  default: statements4;
}
Task-1:

Output-1:

Output-2:

Output-3:


Looping Statements:

 Loops are used to execute the block of code in several times according to the condition given in the loop.
1.For loop:
Syntax: for( intialization; condition; increment decrement)
{
statements;
}
2. While
Syntax: While (condition)
{
statements;
  incrementation
}
3. Do While
Syntax: do
{
statements;
}

While (condition);

Task-1: Using For loop


Output


Task-2: Using While loop

Output: