Home UP BOARD Question Papers NCERT Solutions CBSE Papers CBSE Notes NCERT Books Motivational

Flow of Control in C, C++, and Java, Class 11 Nnotes PDF Downloa

Flow Of Control In C, C++, And Java, Class 11 Nnotes PDF Download

Chapter 2 : Part 1 Flow of Control in C, C++, Java, and Code wiht programming Class 11 Nnotes PDF Download

Flow of Control in C, C++,  and Java,
Class 11 Nnotes PDF Download

 

PROGRAMMING CONSTRUCT
1. SEQUENCE
2. SELECTION
3. ITERATION

Decision Making Statements ( Selection Construct) :-

There are two types of decision making statements in Java. They are:
· if statements
· switch statements

The if Statement:

An if statement consists of a Boolean expression followed by one or more statements.
Syntax:
The syntax of an if statement is:

if statement

If the Boolean expression evaluates to true then the block of code inside the if statement will be executed. If not the first set of code after the end of the if statement (after the closing curly brace) will be executed.
Example:

if statement in java

The if...else Statement:

An if statement can be followed by an optional else statement, which executes when the Boolean expression is false. Syntax: The syntax of an if...else is: 

IF ELSE STATEMENT
IF else statement in java

The if...else if...else Statement:

An if statement can be followed by an optional else if...else statement, which is very useful to test various conditions using single if...else if statement. When using if , else if , else statements there are few points to keep in mind. · An if can have zero or one else's and it must come after any else if's.
· An if can have zero to many else if's and they must come before the else.
· Once an else if succeeds, none of the remaining else if's or else's will be tested. Syntax:
The syntax of an if...else is: 

The syntax of an if...else is

Example:

Example of java

Nested if...else Statement:

It is always legal to nest if-else statements which means you can use one if or else if statement inside another if or else if statement. Syntax:- The syntax for a nested if...else is as follows: 

Nested if...else Statement

You can nest else if...else in the similar way as we have nested if statement. Example:

You can nest else if...else in the similar way as we have nested if statement.

The switch Statement :-

A switch statement allows a variable to be tested for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case. Syntax: The syntax of enhanced for loop is: 

The switch Statement:

The following rules apply to a switch statement:
· The variable used in a switch statement can only be a byte, short, int, or char.
· You can have any number of case statements within a switch. Each case is followed by the value to be compared to and a colon.
· The value for a case must be the same data type as the variable in the switch and it must
be a constant or a literal.
· When the variable being switched on is equal to a case, the statements following that case
will execute until a break statement is reached.
· When a break statement is reached, the switch terminates, and the flow of control jumps
to the next line following the switch statement.
· Not every case needs to contain a break. If no break appears, the flow of control will fall
through to subsequent cases until a break is reached.
· A switch statement can have an optional default case, which must appear at the end of the
switch. The default case can be used for performing a task when none of the cases is true. No
break is needed in the default case.
Example

A switch statement can have an optional default case, which must appear at the end of the

Iteration Construct :-

1. Java while Loop

The while loop or while statement continually executes a block of statements while a particular condition is true. The while syntax can be written as: 

while (expression)
{
statement(s)
}

The while loop evaluates expression, which must return a boolean value. If the while loop expression returns true, then the statements with in the while block will be executed. The while loop continuously executes the statements within the block, until the expression returns false. Here is a simple while loop example, which executes until i value became 10: 

int i=0;
while(i < 10){
//this block will executed until
//i value became 10
System.out.print(i+" ");
i=i+1;
}
Output:
0 1 2 3 4 5 6 7 8 9

2. Java do-while Loop :- A do-while loop is similar to a while loop, except that a do-while loop is guaranteed to execute at least one time. The difference between do-while and while loop is that do-while evaluates its condition at the bottom of the loop instead of the top. Therefore, the statements within the do block are always executed at least once.
Here is the syntax to write do-while loop: 

do
{
statement(s)
}
while (expression);

}
While (expression);

The do-while statement evaluates expression, which must return a boolean value. If the expression is true, the flow of control goes back to the do, and the statements within the loop executes again. This process repeats until the expression returns false. Here is a simple do-while example 

int i = 0;
do {
System.out.print(i+" ");
i=i+1;
} while(i<10);

3. Java for Loop :-

The for statement or for loop provides a way to iterate over a range or list of values. Using for loop you can repeatedly loops until a particular condition is satisfied. The general form of the for statement can be expressed as follows: for (initialization; condition
for terminating; loop increment)
{
statement(s) 
}

In the above statement, initialization expression initializes the loop; it is executed only once, as the loop begins. When the termination condition returns false, then the loop terminates. The increment expression is invoked after each iteration through the loop. Here you can either increment or decrement a value. Here is a simple for loop example to display numbers from 1 to 10. 

for(int i=1;i<=10;i++){
System.out.print(i+" ");
}
System.out.println( );
/**
* another example to increment by 2 steps
*/
for(int i=1;i<=10;i=i+2){
System.out.print(i+" ");
}
System.out.println( );
/**
* Below loop prints the numbers in reverse order
*/
for(int i=10;i>0;i--){
System.out.print(i+" ");
}
System.out.println( )

Here is a simple for loop example to display numbers from

Statement for Jump:--
1. break statement in java:-

The break statement is one of the control statement in java. The break statement is generally used to break the loop before the completion of the loop. The break statement is used when we want to jump out of a single loop or single case in switch statement. Here is a simple example for break statement:

Statement for Jump:--
output

2. continue statement in java:-

The continue statement skips the current iteration of a for, while , or do-while loop. The moment it encounters continue statement, it skips the rest of the statements in the loop and evaluates the expression for next iterations. The difference between break and continue statements are, break statement comes out of the loop, continue statement skips the current iteration and jumps to the next iteration in a single loop. Here is a simple example for continue statement: 

output result of the java

Notes Flow of Control in C, C++, and JavaDownload PDF


Please send your queries to ncerthelp@gmail.com you can aslo visit our facebook page to get quick help. Link of our facebook page is given in sidebar


Class and Subject List

Ncert Solution for class 6 to 12 download in pdf

CBSE Model test papars Download in pdf

NCERT Books Free Pdf Download for Class 5, 6, 7, 8, 9, 10 , 11, 12 Hindi and English Medium

Mathematics Biology Psychology
Chemistry English Economics
Sociology Hindi Business Studies
Geography Science Political Science
Statistics Physics Accountancy

CBSE Syllabus Class 6 to 9, 10, 11, 12 Maths, Science, Hindi, English ...

Last year CBSE Question paper for Class 6 to 9, 10, 11, 12 Maths, Science, Hindi, English ...

Important Links

Follow Us On

Face book page ncerthelp twitter page youtube page linkdin page

NCERT CBSE News

NCERT CBSE News

Please Share this webpage on facebook, whatsapp, linkdin and twitter.

Facebook Twitter whatsapp Linkdin

Copyright @ ncerthelp.com A free educational website for CBSE, ICSE and UP board.