Return to site

Loops In C Programming Ppt

broken image


  • An entry control loop checks the condition at the time of entry and if condition or expression becomes true then control transfers into the body of the loop.
  • Such type of loop controls entry to the loop that's why it is called entry control loop.

In computer programming, loops are used to repeat a block of code. For example, let's say we want to show a message 100 times. Then instead of writing the print statement 100 times, we can use a loop. That was just a simple example; we can achieve much more efficiency and sophistication in our programs by making effective use of loops.

Loops In C Programming Ppt

Do while loop c programming
  • A loop is used for executing a block of statements repeatedly until a given condition returns false.
  • Beware the endless loop! When a C program enters an endless loop, it either spews output over and over without end or it sits there tight and does nothing. Well, it's doing what you ordered it to do, which is to sit and spin forever. Sometimes, this setup is done on purpose, but mostly it happens because of programmer error.
  • Loops. Within a method, we can alter the flow of control using either conditionals or loops. The loop statements while, do-while, and for allow us execute a statement(s) over and over. Like a conditional, a loop is controlled by a boolean expression that determines how many times the statement is executed.
  • The following are the main looping statements available in this category:
Ppt

While loop

  • The while loop is the simplest looping structure
  • It is of entry control looping structure
  • If we have to execute some statements repeatedly as long as certain condition become true we can use the while loop.
  • In the while loop the given expression will be check at the time of the loop entry, if given expression becomes true then control will transfer into the loop body.
  • The statement inside the loop body will be executed.
  • The counter value will be modified and again given expression will be checked to enter in to the loop.
  • This process will continue until the given expression become false.
  • The while loop contains only expression part ,initialization will be done before the while loop

Loops In C Programming Ppt Presentation

Syntax:

Example:

Loops In C Programming Ppt
  • The following program demonstrates use of while loop to print multiplication table.

For loop

  • For loop is the most powerful and flexible looping structure.
  • We can perform any complex task using for loop.
  • It has the following from:

Syntax:

Mixmeister fusion 2019. Example:

  • For loop contains three different parts: initialization, condition and inc/dec part.
  • When the loop executes for the first time, initialization of the counter variable will be done after that expression given into the condition part is tested, if test expression evaluate to true, control will enter into the loop body.
  • The statements inside the loop will be executed.
  • After that control will transfer to the third part where counter value will be either incremented or decremented.
  • With the modified counter value test expression will be check again to enter into the loop.
Ppt
  • A loop is used for executing a block of statements repeatedly until a given condition returns false.
  • Beware the endless loop! When a C program enters an endless loop, it either spews output over and over without end or it sits there tight and does nothing. Well, it's doing what you ordered it to do, which is to sit and spin forever. Sometimes, this setup is done on purpose, but mostly it happens because of programmer error.
  • Loops. Within a method, we can alter the flow of control using either conditionals or loops. The loop statements while, do-while, and for allow us execute a statement(s) over and over. Like a conditional, a loop is controlled by a boolean expression that determines how many times the statement is executed.
  • The following are the main looping statements available in this category:

While loop

  • The while loop is the simplest looping structure
  • It is of entry control looping structure
  • If we have to execute some statements repeatedly as long as certain condition become true we can use the while loop.
  • In the while loop the given expression will be check at the time of the loop entry, if given expression becomes true then control will transfer into the loop body.
  • The statement inside the loop body will be executed.
  • The counter value will be modified and again given expression will be checked to enter in to the loop.
  • This process will continue until the given expression become false.
  • The while loop contains only expression part ,initialization will be done before the while loop

Loops In C Programming Ppt Presentation

Syntax:

Example:

  • The following program demonstrates use of while loop to print multiplication table.

For loop

  • For loop is the most powerful and flexible looping structure.
  • We can perform any complex task using for loop.
  • It has the following from:

Syntax:

Mixmeister fusion 2019. Example:

  • For loop contains three different parts: initialization, condition and inc/dec part.
  • When the loop executes for the first time, initialization of the counter variable will be done after that expression given into the condition part is tested, if test expression evaluate to true, control will enter into the loop body.
  • The statements inside the loop will be executed.
  • After that control will transfer to the third part where counter value will be either incremented or decremented.
  • With the modified counter value test expression will be check again to enter into the loop.

While Loop In C Programming Example Ppt

  • This process will be repeated until condition becomes false.
  • Once the condition becomes false, the loop will be skipped and statement following by for loop will be executed.
  • The initialization will be performed only once when loop encounters first time.
  • For loop also allows specify multiple condition as well as complex expression to be tested.
  • We can also skip any of the part of the loop as per our requirement.
  • The following example provides multiple initialization and expression to be tested.
  • for loop can also be executed either in straight forward or in reverse manner similar to while loop.
  • The following is the same program to print multiplication table using for loop.




broken image