SlideShare a Scribd company logo
ENG : BASMA ROSHDY
In programming often requires repeated
execution of a sequence of operations. A loop
is a basic programming construct that allows
repeated execution of a fragment of source
code. Depending on the type of the loop, the
code in it is repeated a fixed number of times
or repeats until a given condition is true
(exists).
One of the simplest and most commonly used
loops is while.
while (condition)
}
loop body;
}
// Initialize the counter
int counter = 0;
// Execute the loop body while the loop condition holds
while (counter <= 9)
{
// Print the counter value
Console.WriteLine("Number : " + counter);
// Increment the counter
counter++;
}
Number : 0
Number : 1
Number : 2
Number : 3
Number : 4
Number : 5
Number : 6
Number : 7
Number : 8
Number : 9
Console.Write("n = ");
int n = int.Parse(Console.ReadLine());
int num = 1;
int sum = 1;
Console.Write("The sum 1");
while (num < n)
{
num++;
sum += num;
Console.Write(" + " + num);
}
Console.WriteLine(" = " + sum);
N = 17
The sum 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11
+ 12 + 13 + 14 + 15 + 16 + 17 = 153
The do-while loop is similar to the while loop,
but it checks the condition after each
execution of its loop body. This type of loops
is called loops with condition at the end
(post-test loop). A do-while loop looks like
do
{
executable code;
}
while (condition);
Console.Write("n = ");
int n = int.Parse(Console.ReadLine());
Console.Write("m = ");
int m = int.Parse(Console.ReadLine());
int num = n;
long product = 1;
do
{
product *= num;
num++;
} while (num <= m);
Console.WriteLine("product[n...m] = " + product);
n = 2
m = 6
product[n...m] = 720
Console.Write("n = ");
int n = int.Parse(Console.ReadLine());
decimal factorial = 1;
do
{
factorial *= n;
n--;
} while (n > 0);
Console.WriteLine("n! = " + factorial);
For-loops are a slightly more complicated than
while and do-while loops but on the other
hand they can solve more complicated tasks
with less code. Here is the scheme describing
for-loops:
for(int i=0;i<10;i++)
{
/*loopbody*/
}
for (initialization; condition; update)
}
loop's body;
{
for (int num = 0; num < 10; num++)
}
// Loop body
}
for (int i = 0; i <= 10; i++)
}
Console.Write(i + " ");
{
The result of its execution is the following:
0 1 2 3 4 5 6 7 8 9 10

More Related Content

DOCX
timingExercise
PDF
3 rd animation
PPTX
Lecture 3
PPTX
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
PDF
Rcpp11 useR2014
PPTX
Lecture 4
PDF
Do while loop
 
PDF
Libtcc and gwan
timingExercise
3 rd animation
Lecture 3
.NET Core Summer event 2019 in Brno, CZ - Async demystified -- Karel Zikmund
Rcpp11 useR2014
Lecture 4
Do while loop
 
Libtcc and gwan

What's hot (20)

DOCX
Java Code for Sample Projects Methods
PDF
Using zone.js
PPT
Server Side JavaScript: Ajax.org O3.
PPT
Server Side JavaScript: Ajax.org O3
PDF
2Bytesprog2 course_2014_c8_units
PDF
Probability of finding a single qubit in a state
PDF
Chapter24 operator-overloading
PDF
ClojureScript - A functional Lisp for the browser
PDF
Inc decsourcefile
DOCX
Jarmo van de Seijp Shadbox ERC223
PDF
R/C++ talk at earl 2014
DOCX
Assignement of programming & problem solving(3)a.z
PPTX
Tail Recursion in data structure
PPT
Removal Of Recursion
PDF
Продвинутая отладка JavaScript с помощью Chrome Dev Tools
PDF
Why is a[1] fast than a.get(1)
PDF
Rubinius @ RubyAndRails2010
PDF
Clojure+ClojureScript Webapps
PDF
Debugging JavaScript with Chrome
Java Code for Sample Projects Methods
Using zone.js
Server Side JavaScript: Ajax.org O3.
Server Side JavaScript: Ajax.org O3
2Bytesprog2 course_2014_c8_units
Probability of finding a single qubit in a state
Chapter24 operator-overloading
ClojureScript - A functional Lisp for the browser
Inc decsourcefile
Jarmo van de Seijp Shadbox ERC223
R/C++ talk at earl 2014
Assignement of programming & problem solving(3)a.z
Tail Recursion in data structure
Removal Of Recursion
Продвинутая отладка JavaScript с помощью Chrome Dev Tools
Why is a[1] fast than a.get(1)
Rubinius @ RubyAndRails2010
Clojure+ClojureScript Webapps
Debugging JavaScript with Chrome
Ad

Similar to Loops (1) (20)

PPT
06 Loops
PPTX
06.Loops
PDF
Programming Fundamentals presentation slide
PPTX
1.3 core programming [identify the appropriate method for handling repetition]
PPT
C Sharp Jn (3)
PPT
Loops
DOCX
Oops pramming with examples
PPT
Control Statements, Array, Pointer, Structures
ZIP
DOCX
C# console programms
PPTX
C++ loop
PDF
Lenguaje de Programación en C Presentacion
PDF
04-Looping( For , while and do while looping) .pdf
PPTX
Oop object oriented programing topics
PDF
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
PPTX
Chapter i c#(console application and programming)
PPTX
Loop control structure
PPTX
Computational PhysicsssComputational Physics.pptx
DOC
3. control statement
PPTX
#c training and knowlege of c-sharp program.pptx
06 Loops
06.Loops
Programming Fundamentals presentation slide
1.3 core programming [identify the appropriate method for handling repetition]
C Sharp Jn (3)
Loops
Oops pramming with examples
Control Statements, Array, Pointer, Structures
C# console programms
C++ loop
Lenguaje de Programación en C Presentacion
04-Looping( For , while and do while looping) .pdf
Oop object oriented programing topics
C++ and OOPS Crash Course by ACM DBIT | Grejo Joby
Chapter i c#(console application and programming)
Loop control structure
Computational PhysicsssComputational Physics.pptx
3. control statement
#c training and knowlege of c-sharp program.pptx
Ad

Recently uploaded (20)

PDF
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
PPTX
Cell Structure & Organelles in detailed.
PPTX
Institutional Correction lecture only . . .
PDF
Microbial disease of the cardiovascular and lymphatic systems
PPTX
Pharma ospi slides which help in ospi learning
PDF
Anesthesia in Laparoscopic Surgery in India
PDF
Sports Quiz easy sports quiz sports quiz
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PPTX
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Microbial diseases, their pathogenesis and prophylaxis
PPTX
PPH.pptx obstetrics and gynecology in nursing
PPTX
Pharmacology of Heart Failure /Pharmacotherapy of CHF
PDF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PDF
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
PPTX
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES
The Lost Whites of Pakistan by Jahanzaib Mughal.pdf
Cell Structure & Organelles in detailed.
Institutional Correction lecture only . . .
Microbial disease of the cardiovascular and lymphatic systems
Pharma ospi slides which help in ospi learning
Anesthesia in Laparoscopic Surgery in India
Sports Quiz easy sports quiz sports quiz
Renaissance Architecture: A Journey from Faith to Humanism
school management -TNTEU- B.Ed., Semester II Unit 1.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
human mycosis Human fungal infections are called human mycosis..pptx
Supply Chain Operations Speaking Notes -ICLT Program
Microbial diseases, their pathogenesis and prophylaxis
PPH.pptx obstetrics and gynecology in nursing
Pharmacology of Heart Failure /Pharmacotherapy of CHF
Chapter 2 Heredity, Prenatal Development, and Birth.pdf
STATICS OF THE RIGID BODIES Hibbelers.pdf
Black Hat USA 2025 - Micro ICS Summit - ICS/OT Threat Landscape
BOWEL ELIMINATION FACTORS AFFECTING AND TYPES

Loops (1)

  • 1. ENG : BASMA ROSHDY
  • 2. In programming often requires repeated execution of a sequence of operations. A loop is a basic programming construct that allows repeated execution of a fragment of source code. Depending on the type of the loop, the code in it is repeated a fixed number of times or repeats until a given condition is true (exists).
  • 3. One of the simplest and most commonly used loops is while. while (condition) } loop body; }
  • 4. // Initialize the counter int counter = 0; // Execute the loop body while the loop condition holds while (counter <= 9) { // Print the counter value Console.WriteLine("Number : " + counter); // Increment the counter counter++; }
  • 5. Number : 0 Number : 1 Number : 2 Number : 3 Number : 4 Number : 5 Number : 6 Number : 7 Number : 8 Number : 9
  • 6. Console.Write("n = "); int n = int.Parse(Console.ReadLine()); int num = 1; int sum = 1; Console.Write("The sum 1"); while (num < n) { num++; sum += num; Console.Write(" + " + num); } Console.WriteLine(" = " + sum);
  • 7. N = 17 The sum 1 + 2 + 3 + 4 + 5 + 6 + 7 + 8 + 9 + 10 + 11 + 12 + 13 + 14 + 15 + 16 + 17 = 153
  • 8. The do-while loop is similar to the while loop, but it checks the condition after each execution of its loop body. This type of loops is called loops with condition at the end (post-test loop). A do-while loop looks like do { executable code; } while (condition);
  • 9. Console.Write("n = "); int n = int.Parse(Console.ReadLine()); Console.Write("m = "); int m = int.Parse(Console.ReadLine()); int num = n; long product = 1; do { product *= num; num++; } while (num <= m); Console.WriteLine("product[n...m] = " + product);
  • 10. n = 2 m = 6 product[n...m] = 720
  • 11. Console.Write("n = "); int n = int.Parse(Console.ReadLine()); decimal factorial = 1; do { factorial *= n; n--; } while (n > 0); Console.WriteLine("n! = " + factorial);
  • 12. For-loops are a slightly more complicated than while and do-while loops but on the other hand they can solve more complicated tasks with less code. Here is the scheme describing for-loops: for(int i=0;i<10;i++) { /*loopbody*/ }
  • 13. for (initialization; condition; update) } loop's body; {
  • 14. for (int num = 0; num < 10; num++) } // Loop body }
  • 15. for (int i = 0; i <= 10; i++) } Console.Write(i + " "); { The result of its execution is the following: 0 1 2 3 4 5 6 7 8 9 10