0% found this document useful (0 votes)
6 views

Programming Presentation

The document presents a group project on the topic of loops in computer programming, submitted by a class of chemistry students. It covers the definition of loops, their types (while loop, do-while loop, and for loop), and provides examples and syntax for each type. The document emphasizes the importance of loops in programming for executing repetitive tasks based on specified conditions.

Uploaded by

shahzaib2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
6 views

Programming Presentation

The document presents a group project on the topic of loops in computer programming, submitted by a class of chemistry students. It covers the definition of loops, their types (while loop, do-while loop, and for loop), and provides examples and syntax for each type. The document emphasizes the importance of loops in programming for executing repetitive tasks based on specified conditions.

Uploaded by

shahzaib2000
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 21

PRESENTATION OF GROUP 1

• Roll numbers # 2, 3, 4, 5, 6, 7
• Class# Bs chemistry (2A)
• Subject # computer application and programming
• Topic # LOOP
• Submitted To # Prof Hafeez ur Rehman
CONTENTS

• LOOPING STATEMENT
• WHILE LOOP
• DO WHILE LOOP
• FOR LOOP
LOOP

• Definition: Loop is a statement which is used to


repeat the single or multiple statement.
o It is also called repetitive structure.
o Loop are among the most basic and powerful
programming concept.
o A loop in a computer program is an instruction that
repeats until a specified condition is reached.
o In a loop structure the loop asks a question. If the
answer requires actions it is executed.
1
Initialization
(Start Value)
2
Condition
(Last Value)

There things are


necessary for all loops

3
Increment/
Decrement
(Increase/Decrease)
TYPES OF LOOP
There are three types of loop
2 3
1

While loop Do-while loop For-loop


In most computer programming
languages, a while loop is control initialization;
flow statement that allows code
while(condition)
to be executed repeatedly based
on a given condition.
{
Statement;
Statement;

6
Increase/Decrease;
Free presentation PowerPoint - SLIDESELLER.COM }
WHILE LOOP

 While is a loop that is represented as long as an expression is true.


 An expression is a statement that have values.
PROCEDURE
Step 1 In while loop, condition is evaluated first and if
it returns true then the statements inside the loop
execute, this happens repeatedly until the condition
returns false.

Step 2 When the condition returns false, the control


comes out of loop and jumps to the next statement in
the program after while loop.

Step 3 The important point to note when using while


loop is that we need to use increment or decrement
statement inside while loop so that the loop variable
gets changed on each iteration and at some point
condition returns false.

Step 4 This way we end the execution of while loop


DO –WHILE LOOP
Definition
The do while loop checks the condition at the end of loop, This
means that the statements inside the loop body will be executed at
least once even, if condition is not true.
Syntax
initialization;
Do
{
statement;
statement;
increase/decrease;
}
CONTINUE…..
If the condition is True, the control go back to beginning of the
loop.
If the condition is False, the control breaks out of the loop.
It means that the statement inside the loop are executed
before the condition is tested.
So the do-while loop should be used in all sccoarious .where
the loop body need to be executed at least once.
Often in a menu driven program when actions are supposed to
be taken repeatedly based upon the user input.
We need a do-while loop to understand which action the user
to take.
EXAMPLE….
Q: Write a program to display the values from 1 to 10.
EXAMPLE…..
FOR- LOOP

Definition
Execute a sequence of statements multiple times and
abbreviates the code that manages the loop variable.

It is also an entry-controlled loop.


All for loops are executed in following sequence
1. It execute initialization statements.
2. It check the test condition if true than go to step:3 otherwise
step:4
CONTINUE…….

3. Execute body of loop and go to step 2 after increment or decrement.


4. Other statement of the program.
SYNTAX
Syntax refers to the spelling and grammar of a programming
language. Computer are inflexible machines that understand what you
type only, if you type it in the exact form that the computer expects.
The expected form is called Syntax.
The syntax of a for loop in C programming language is
CONTINUE…..

For loop has three parts of syntax:


Initializer is executed at start of loop.

Loop condition is tested before iteration to decide whether to


continue or terminate the loop.

Increment is executed at the end of each loop iteration.


CONTINUE…..

SYNTAX
For (initialization; condition ;
increment/decrement)
{
Statement ;
}
EXAMPLE…..
 Write a program to display the values from 1to 10.
EXAMPLE……

Write a program to display the all factors of 5 between 60 to


120.
EXAMPLE…..

Write a program to print the values from 30 to 1.

You might also like