Sunday, 30 August 2020

What are nesting of loops ?

     Nested loops 




So here we’ll be studying the nesting of loops with their syntax and with their uses 


While learning any programming language you have often heard the word “nested loops” and many of the beginner programmer stucks hear and struggle to learn the nesting of loops 


So hear i’ll tell you the meaning of nesting of loops and their implementation in the program 


A nested loop is a loop in which an another loop is present means it has two or more loops inside a loop 


The first and mani loop is called as outer loop and the second loop which is present inside the inner body of the outer loop is called inner loop 


Hear the outer loop triggers the inner loop which executes to completion and then the second pass the outer loop triggered the inner loop and this process repeats till the outer loop is finished 


To interrupt both the loops in between we can use the break statement on between the line of outer or inner loop. 


This statement is used in the programming to run a loop multiple times 


Now we’ll understand the implementation of nesting for loops with the help of syntax of nested for loop. 


syntax :- nested for loop


for (statement1;  statement2; statement3){

//code blocks

for (statement1; statement2; statement3){

//code blocks 

  }

}


Now further we’ll learn to implement the nested for loop in our program with the help of an example 


i.e. :- so we have to write a program which prints the counting of 1 to10 5 times then we use nesting of the condition to run a particular loop for multiple times 


ans :- below with the help of program one can easily understand the implementation of a nesting of loops hear we have used the java code to solve the above example 


public class Nestedforloop{

public static void main (string [ ]args){

for (int j =1; j<=5; j++){ 

 for (inti=1; i<=10; i++){

system.out.print (i+” “);

   }

system.out.println();

    }

  }

}


Hear i have explained the nesting of loops by taking an example of nested for loop you can implement nesting of other loops as well 


Nesting of loops are also used for printing patterns in our program 


Hopefully the above illustrated information and examples helped you to understand the nesting of loops as well as the use of these loops in our program 


Stay connected with us for such useful knowledgeable content 


Thankyou 


BY :- ADARSH GUPTA 

Saturday, 22 August 2020

What are loops? Why do we need loops in our program ?

 What are loops? Why do we need loops in our program ? 




While programming in any language whether it is c , c++ , java , python ,etc. we often heard the word loops. 

So hear we’ll learn about loops and also we’ll learn the uses of loops in our program.


So by hearing the word loop the thing which comes in our mind is something related to the spiral, trap or hinge.


Now we can relate the word loop in programming that loops are related to trap our code in our program to check or to perform some task till some particular condition or something like that. 


Now let’s move towards the proper defination of the loops 


Loops:- loops are used to execute a set of statement until a particular condition is satisfied 


Hopefully with the above definition you have understand the meaning of loops 

Now let’s move towards the types of loops 


So hear we will study the three types of loop’s which is as follows 


  1. For loop 

  2. While loop

  3. Do while loop 


So let’s begin with the very first in our list which is for loop 


  • For loop :- with the help of syntax below try to understand the pattern of statements and conditions  


Syntax :-

                 for ( statement1; statement2 ; statement3)

                    {code block }


Where the statement1 shows the initialization of the loop, statement2 states the condition of the loop and statement3 is for reinitialization of the loop which is either increment or decrement. 


While using this for loop in your program you need to remember some minor mistakes made by us during programming which will throw some unexpected errors or may be give some unexpected results


So, the very first thing which you need to keep in mind is if the first statement is missing which is initialization of the loop then your program will throw an error at compile time so you need to take proper care of the initialisation of your loop. 


Now come to the next common mistakes which is not good for our program 

If the second and third statement is missing in our program which indicates condition and reinitialisation of the loop then our program will run infinitely till the completely filling of heap memory of our system and again which is not good for our program 


Now with the help of above syntax try to implement a for loop in your program and letter on use this to solve some simple or beginner level questions


Now we will try to understand the implementation and uses of for loop with the help of some examples 


  1. We have to write a program to print the factorial of a number with the help of for loop 


ans.:-

Let the number be “n” and the factorial of the number is 

n! = n(n-1)(n-2).......


Now we’ll write the code for this problem using java 


Public class factorial {

public static void main (string[]args){

scanner sc= new scanner (system.in);

int n = Sc. nextInt(); 

int factorial = 1; 

for (int i= n; i>=1; i-- ){

factorial = factorial * i

          } 

system.out.println(factorial);

      }

}         


The above code will print the factorial of the number given by the user 


Now we’ll see the use of break and continue statements which is also a very helpful role in our program. 


So very first we’ll see the use of break statement 


  • Break :- break condition is used to move out of the loop and executes the next statement after the loop.


Syntax :- let’s try to understand the use of break statement with the help of syntax below 


for (statement1; statement2; statement3){

// code blocks

if (condition){

break;

    }

}


Let's see the use of break statement for the better understanding of break statement


i.e. :- use of break condition 


for (int i=1;i<=100;i++){

if (i=35){

break;

    }

system.out.println(i);

  }

}


The above written java code will print the numbers till 34 at the point when number becomes equal to 35 then the program will stop printing the numbers after 35 


Now lets see the implementation of continue statement in our program 


  • Continue :- the continue statement is used to skips the current executing loop and moves towards the next loop


Syntax :- below with the help of syntax let’s try to understand the use and implementation of continue statement 


for (statement 1; statement2; statement3){

//code block

if (condition){

continue;

    }

}


Now we’ll see the use of continue and understand the implementation of continue statement with the help of an example 


i.e. :- write a program to print the numbers from 1 to 100 but we have to skip the number between 40 to 50 


ans :- so for this example we’ll using a java code to solve the above problem 


public class continue {

public static void main (string[]args){

for (int i=1;i<=100;i++){

if (i>=40 && i<=50)

continue;

}

system.out.println(i);

  }

}


So the above written program will print the number between 1 to 100 and skip the number between 40 to 50. 


  • While loop :- with the help of below syntax let’s try to understand while loop 


Syntax :- 

initialisation 

while (condition){

//code inside the body of while loop

reinitialisation 

}


In the above syntax we have seen the the while loop in a program is used to check a condition in program now we’ll understand the use of while loop in our program with the help of an example 


i.e. : - we have to write a program to find the sum of the digits of a number that is for a given number 123 the sum is 6 


Now we will study the do while loop with the help of an example and with the help of syntax 


  • Do while loop :- in do while loops one condition runs very first and then it comes to the another condition and checks that condition 


In do while loop the statement verifies at least one condition then after it comes to the another condition 


In this loop the statement is executed at least one time 


Now below with the help of syntax we’ll try to understand the implementation of do while loop in our program 


Syntax :- 

do {

// codes inside the body if do while loop 

} while (condition);


Now we’ll see the use of do while loop with the help of an example 


i.e. :- we have to write a program which checks whether a number is zero or not 


ans :- so hear we will write a program using do while loop to check weather the number is zero or not and the language which we are using hear is java 


public class Do While Loops {

public static void main (string [ ]args){

int n =0; 

do {

system.out.println(“n is +n”);

    }

while(n!=0);

  }

}


Hopefully with the help of above mentioned information i have tried to understand the loops and it’s implementation with the help of examples and syntaxes 

Now you will be much familiar with the syntaxes and the implementation of the loops so you can use these loops in your own program.


At the last to become more familiar with the programming you need to do practice with your own without practice you can't get the best result out of it so practice more and more to get familiar with programming 


Stay connected with us in future we will bring more such valuable content 

Thankyou 


BY :- ADARSH GUPTA 

Saturday, 15 August 2020

What are conditional statements and what are the uses of conditional sentences ?

 What are conditional statements and what are the uses of conditional sentences ? 



So, here we’ll study about the conditional statements and also we’ll see the uses of these conditional statements. 


We’ll try to understand the conditional sentences by taking the examples of nested if else statements and switch-case. 


While programming in any language we often suffer with the complex problems in our program 


To overcome with the difficulty of these complex problems and to reduce the complexity of our program conditional statements are used  


Below we’ll understand the conditional statement with the help of nested if else and switch case 


  1. Nested if-else :- 


In nested if-else condition two or more than two conditions are checked the syntax of nested if-else is given below


Syntax :- 

if ( condition 1 ) {  code block

                if ( condition 2 ) { code. block }

                     else { code block }

                }


  • Nesting in ternary operators :- 


syntax :- 

variable = ( condition 1) ? ( condition 2 ) ? exp 1 ; exp 2

( condition 3 ) ? exp 3 ; exp 4 ;


e.i. :- result = a > b ? a > c ? a : c ; b > c ? b : c ;


  1. Switch case :-

 

Switch case are used to check or to implement various cases in a program 

it is particularly used to switch the various expressions in our program

let’s try to understand the use of switch case with the help of syntax below

 

syntax :- 

            switch (exp) {

              case value 1;

                 // statement 

                  break; 

                   case value2; 

                    // statements

                     break;

                      ------

                       default; 

                         //statements

                   }


  • With the help of switch case we can also print multiple statements in our program :-


So to print multiple statement within one input we have to escape the use of “break” after the completion of one condition 

In this manner we can easily print multiple statements in our program. 

e.i. :-

       switch (case)

          case1:

           case2:

            case3:

          statement

          break; 

 

With the above illustrated example one can easily understand the method to print multiple statement with single input 

also in the above illustrated example you have noticed that there is no break statement in between the case 


I hope the above mentioned information helps you to understand the conditional statements

stay connected with us for such useful information also share these informations to the needy  

Thankyou


BY :- ADARSH GUPTA







Sunday, 2 August 2020

How to kill the bacteria present in water by bleaching powder method ?

How to kill the bacteria present in water by bleaching powder method ? 


The normal water may be contimaneted by many harmfull bacteric which is not good for our health also it may affect oue health at very serious level 


So for the consumption of water it is required to make the drinking water free from all kinds of bacteria so that we can overcome with the harmfull desiease happens with the consumption of contimenated water 


So today we will discuss the bleachig powder method as a disinfectant of water 


Bleaching powder which is also known as calcium hypochlorate 


It contains about 30 % available chlorine it reacts with water to produce hypochlorous acid which is a powerfull disinfectant due to its property of liberation of nacent oxygen 


Also it has the potential to sterilize much water at a time around 1 kg of bleaching powder is sufficient to sterilize one million liters of water. 


The necent oxygen which produce in this reaction destroys the pathogens by oxidation the anion of the reaction repture the cell membrane of the paythogenic bacteria present in the water also the chlorine it self has the potential of powerfull anti-microbial activity. 


Disadvantages :- 


Bleaching powder method has a very good potential to strilize a large amount of water at a time but instead of this it has some disadvantages with them which we will be discuss below 


  • By the use of bleaching poweder it introduces calcium ion in water which is responsible for the hardness and Ph of the water 

  • Excess use of bleaching powder in water produces disagreeable odour and bad taste and cause irritation therefor a calculated amount of bleachin powder is added to the water 

  • Due to the continuous decomposition during storage its chlorine content goes on changing. that's why before addition of bleaching powder its chlorine content should be analyze properly 


That's all you need to take care while using the chlorination method for the sterilization of water 


I hope the above mentioned information help to go through the bleaching powder method and helps you to identify the reason of different taste and odour of the water when you consume that kind of water next time 

One thing you should keep remember that the odour and taste of water may be affected by many other reasons also 

Thankyou 


BY :- ADARSH GUPTA


Linking Words/ Conjunctions

  Linking Words/ Conjunctions Conjunctions are words that link other words, phrases, or clauses together. Kinds of conjunctions Conjunctions...