Unit 2 Loop Control Statements LECTURE - PowerPoint PPT Presentation

1 / 8
About This Presentation
Title:

Unit 2 Loop Control Statements LECTURE

Description:

Title: Unit 2 Loop Control Statements LECTURE 16 Author: p k mishra Last modified by: p k mishra Created Date – PowerPoint PPT presentation

Number of Views:55
Avg rating:3.0/5.0
Slides: 9
Provided by: pkm3
Category:

less

Transcript and Presenter's Notes

Title: Unit 2 Loop Control Statements LECTURE


1
Unit 2 Loop Control Statements
LECTURE 16
  • Loop A Loop is defined as a block of statements
    which are repeatedly executed for certain number
    of times.
  • Steps in Loops
  • Loop Variable It is a variable used in the Loop.
  •  
  • Initialization It is the 1st step in which
    starting final value is assigned to the loop
    variable. Each time the updated value is checked
    by the loop itself.
  •  
  • Increment/Decrement It is the numerical value
    added or subtracted to the variable in each round
    of the loop.

2
Unit 2 Loop Control Statements
LECTURE 16
  • Syntax of loop
  • for (expression-1 expression-2 expression-3)
  • statement
  • While
  • expression-1
  • while (expression-2)
  • statement
  • expression-3
  • do-while
  • expression-1
  • do
  • statement
  • expression-3
  • while (expression-2)

3
Unit 2 Loop Control Statements
LECTURE 16
  • for(initialize counter test counter
    increment/decrement counter)
  • The for statements is equivalent to while and
    do-while statements. The only difference between
    for and while is that the letter cheeks the
    logical condition and then executes the body of
    the loop, where as in for statements test is
    always performed at the beginning of the loop.
    The body of the loop may not be executed at all
    times if the condition fails at the beginning.

4
Unit 2 Loop Control Statements
LECTURE 16
  • Q. WAP To Print 5 Natural No using while Loop.
  •  
  • includeltstdio.hgt
  • void main()
  • int n
  • n1
  • while (nlt5)
  • printf( \n Number is d,n)
  • n

5
Unit 2 Loop Control Statements
LECTURE 16
  • Q. WAP To Print 5 Natural No using do-while Loop.
  •  
  • includeltstdio.hgt
  • void main()
  • int n
  • n1
  • do
  • printf( \n Number is d,n)
  • n
  • while (nlt5)

6
Unit 2 Loop Control Statements
LECTURE 16
  • Q. WAP To Print 5 Natural No using for Loop.
  •  
  • includeltstdio.hgt
  • void main()
  • int n
  • for(n1nlt5n)
  • printf( \n Number is d,n)

7
Unit 2 Loop Control Statements
LECTURE 16
  • Q. WAP To Print Odd Even No using for Loop.
  •  
  • includeltstdio.hgt
  • void main()
  • int n
  • for(n1nlt5n)
  • if (n2 0)
  • printf( \n Number is Even d,n)
  • else
  • printf( \n Number is Odd d,n)

8
Unit 2 Loop Control Statements
LECTURE 16
  • Thanks
Write a Comment
User Comments (0)
About PowerShow.com