SlideShare a Scribd company logo
Agenda
1- Warm up Listen to this video about motivating
programmers 5 min
2- ppt teacher demonstrate about loops 20 min
3- Video about how we can use c programming in rea
life projects , automation and solving problems 3 min
4-Students play or act a game about simulating loops
10 min
5- practical work using lap tops through code blocks i
implement a small program work in pairs 10 min
6- use netacade.com to self learn C and get certificate
from CISCO 5 min
7- Questions and answers 20 min
8-Refelection 5 min
9- Home work
LO CS.2.02 - Design
programs involving
decision structures
and loops.
Lesson plan
Warm Up
Listen to this video
motivating programmers
Open Code blocks or
www.Jdoodle.com on
line
Essential Question
1- why we use computers ?
2- what are the tasks , jobs
which can be computerized ?
3- what are Repetitions or loops
4- Distinguish between
while and do while and for
loop
Warm Up
Listen to this video
Off line
On line
Essential Question
How to Perform certain
repetitive tasks , control
all loops by sequence
statements?
7
–While
–Do while
–For
Repetition Statements /
Loops
8
Repetition Statements
• Repetition statements allow us to
execute a statement or a block of
statements multiple times
• Like conditional statements, they are
controlled by boolean expressions
• C has three kinds of repetition
statements:
while
Do while
for
Types of Loops
• Pretest - a logical condition is checked
before each repetition to determine if
the loop should terminate
–while loop
–for loop
• Posttest - a logical condition is
checked after each repetition for
termination
–do-while loop
PreTest vs. PostTest Loops
Pretest Loop
Condition
Action or
Actions
true
f alse
Posttest Loop
Condition
Action or
Actions
true
f alse
11
The while Statement
• A while statement has the following syntax:
• If the condition is true, the statement is
executed
• Then the condition is evaluated again, and if it is
still true, the statement is executed again
• The statement is executed repeatedly until the
condition becomes false
while ( condition )
statement;
Logic of a while Loop
statement
true false
condition
evaluated
5
13
The while Statement
• An example of a while statement:
• If the condition of a while loop is false
initially, the statement is never executed
• Therefore, the body of a while loop will
execute zero or more times
int count = 0;
while (count < 2)
{
printf("Welcome to C programming!");
count++;
}
Trace while Loop
int count = 0;
while (count < 2)
{
printf("Welcome to C programming!");
count++;
}
Initialize count
animation
7
Trace while Loop, cont.
int count = 0;
while (count < 2)
{
printf("Welcome to C programming!");
count++;
}
(count < 2) is true
animation
8
Trace while Loop, cont.
int count = 0;
while (count < 2)
{
printf("Welcome to C programming!");
count++;
}
Print Welcome to Java
animation
9
Trace while Loop, cont.
int count = 0;
while (count < 2)
{
printf("Welcome to C programming!");
count++;
}
Increase count by 1
count is 1 now
animation
10
Trace while Loop, cont.
int count = 0;
while (count < 2)
{
printf("Welcome to C programming!");
count++;
}
(count < 2) is still true since count
is 1
animation
11
Trace while Loop, cont.
int count = 0;
while (count < 2)
{
printf("Welcome to C programming!");
count++;
}
Print Welcome to C programming
animation
12
Trace while Loop, cont.
int count = 0;
while (count < 2)
{
printf("Welcome to C programming!");
count++;
}
Increase count by 1
count is 2 now
animation
13
Trace while Loop, cont.
int count = 0;
while (count < 2)
{
printf("Welcome to C programming!");
count++;
}
(count < 2) is false since count is 2
now
animation
14
Trace while Loop
int count = 0;
while (count < 2)
{
System.out.println("Welcome to Java!");
count++;
}
The loop exits. Execute the next
statement after the loop.
animation
15
Posttest Loop: Do-While
Syntax:
do {
statement(s)
} while (condition);
Corresponds to:
statement
if (!condition) DONE
statement
if (!condition) DONE
...
condition
statement(s)
true
f alse
Using the Do-While
do {
printf(“Enter id# and salary: “);
scanf(“%d %f”,&id,&salary);
printf(“You entered id#%1d and salary
$%.2f, Is this correct? (Y/N) “
,id,salary);
scanf(“ %c”,&ans);
} while (!((ans == ‘Y’) || (ans == ‘y’)));
• Loop always executes at least once
While vs Do-While
• Differences
–where condition tested:
• while (first) - may execute 0 times
• do-while (last) - must execute at least one
time
• Similarities
–one statement executed
–initialization before loop
–update during loop
Pretest Loop: For
• Initialization included in loop header
• Update included in loop header
• Header also includes update
• Syntax:
for ( init ; condition ; update )
statement;
• Generally for loops expected to
execute fixed number of times
(counter-controlled)
For Loop
• Syntax:
for ( init ;
condition ;
update )
statement;
• Init: assignments to
counter variables
• Update: changes to
counter variables
Condition
Statement
true
f alse
Init
Update
For Example
• Printing vertical line
of stars:
for (counter = 0;
counter < 5;
counter++)
printf(“*n”);
counter < 5
printf ("*n");
true
f alse
counter = 0;
counter++;
For Example - Sum of 1 to N
printf(“Number to sum to: “);
scanf(“%d”,&N);
total = 0;
for (I = 1; I <= N; I++)
total += I;
/* total is now 1 + 2 + … + N */
Are we ready to code it?
http://www.stemassiut.info prepared By Mr. Osama Ghandour
30
Game about simulating loops
31
Game about simulating loops
32
For Example - Max of N Scores
printf(“Number of students: “);
scanf(“%d”,&NumStudents);
for (I = 0; I < NumStudents; I++) {
printf(“Enter student score %d: “);
scanf(“%d”,&score);
if (score > max)
max = score;
}
/* max is highest score entered */
Listen to this video
about programming
Arduino
Off line
On line
Directions of Counting
for (I = 10; I >= 1; I--)
printf(“%d…n”,I);
printf(“0 BLASTOFF!n”);
printf(“Enter start, end, inc values: “);
scanf(“%d%d%d”,&lstart,&lend,&linc);
for (I = lstart;
((linc < 0) && (I < lend)) ||
((linc > 0) && (I > lend));
I += linc)
printf(“%dn”,I);
practical work using lap
tops through code blocks
in implement a C small
program work in pairs 20
min
Use netacade.com to self
learn C and get certificate
from CISCO 7 7 min
Online auto answered
quiz 15 min
39
–While
–Do while
–For
Repetition Statements / Loops
Types of loops :
Summary
Reflection
• What is your goal to accomplish in
next week End Using loops in C
programming Language ?
Week2 ch4 part1edited 2020
students create in small
groups a c program
related to their capstone
project .
Home work
+ =
C program
Arduino
Arduino hardware
controller
components of irradiation
system
Home Work
Discuss how to use
Loops in coding
different programs
in a video by using
office mix. 43
Resources
• watch a video that explain different ways
for loops and read in the following links :
https://www.youtube.com/watch?v=Rtww8
3GH0BU
44
Thanks
Mr. Osama Ghandour

More Related Content

PPTX
Pi j1.4 loops
PDF
Why we do monitoring Wrong #osmc edition
PPTX
C# Loops
PDF
Inteligencia artificial 12
PDF
How NOT to Write a Microbenchmark
PPTX
Loops in C.pptx
PPTX
Loops in C Programming Language
PPTX
etlplooping-170320213203.pptx
Pi j1.4 loops
Why we do monitoring Wrong #osmc edition
C# Loops
Inteligencia artificial 12
How NOT to Write a Microbenchmark
Loops in C.pptx
Loops in C Programming Language
etlplooping-170320213203.pptx

Similar to Week2 ch4 part1edited 2020 (20)

PPT
Chapter06.PPT
PPSX
C lecture 3 control statements slideshare
PDF
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
PPT
12 lec 12 loop
DOCX
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
DOCX
loops and iteration.docx
PDF
Loop and while Loop
PPTX
Loops in c programming
PPTX
Loops in Cjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj.pptx
PDF
04-Looping( For , while and do while looping) .pdf
PPTX
Cse lecture-7-c loop
PPTX
The Loops
PDF
Repetition, Basic loop structures, Loop programming techniques
PPTX
While , For , Do-While Loop
PDF
DOCX
itretion.docx
PPTX
Looping statements in C
PDF
Workbook_2_Problem_Solving_and_programming.pdf
PPT
Lecture 13 Loops1 with C++ programming.PPT
PPTX
C Programming: Looping Statements in C Pgm
Chapter06.PPT
C lecture 3 control statements slideshare
Loops in C Programming | for Loop | do-while Loop | while Loop | Nested Loop
12 lec 12 loop
CMIS 102 Hands-On Lab Week 4OverviewThis hands-on lab all.docx
loops and iteration.docx
Loop and while Loop
Loops in c programming
Loops in Cjjjjjjjjjjjjjjjjjjjjjjjjjjjjjjj.pptx
04-Looping( For , while and do while looping) .pdf
Cse lecture-7-c loop
The Loops
Repetition, Basic loop structures, Loop programming techniques
While , For , Do-While Loop
itretion.docx
Looping statements in C
Workbook_2_Problem_Solving_and_programming.pdf
Lecture 13 Loops1 with C++ programming.PPT
C Programming: Looping Statements in C Pgm
Ad

More from Osama Ghandour Geris (20)

PPTX
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
PPT
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
PPT
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansour
PPT
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandour
PPT
Python week 7 8 2019-2020 for grade 10
PPT
Python week 6 2019 2020 for grade 10
PPT
Python week 5 2019 2020 for g10 by eng.osama ghandour
PPT
Python week 4 2019 2020 for g10 by eng.osama ghandour
PPTX
Programming intro variables constants - arithmetic and assignment operators
PPT
Mobile appliaction w android week 1 by osama
PPT
Python week 1 2020-2021
PPT
6 css week12 2020 2021 for g10
PPT
Css week11 2020 2021 for g10 by eng.osama ghandour
PPTX
Cooding history
PPT
Computer networks--network
PPTX
How to print a sketch up drawing in 3d
PPT
Google sketch up-tutorial
PPTX
7 types of presentation styles on line
PPT
Design pseudo codeweek 6 2019 -2020
PPT
Php introduction
functions in python By Eng. Osama Ghandour الدوال فى البايثون مع مهندس اسامه ...
Python week 5 2019-2020 for G10 by Eng.Osama Ghandour.ppt
Python cs.1.12 week 10 2020 2021 covid 19 for g10 by eng.osama mansour
Python cs.1.12 week 9 10 2020-2021 covid 19 for g10 by eng.osama ghandour
Python week 7 8 2019-2020 for grade 10
Python week 6 2019 2020 for grade 10
Python week 5 2019 2020 for g10 by eng.osama ghandour
Python week 4 2019 2020 for g10 by eng.osama ghandour
Programming intro variables constants - arithmetic and assignment operators
Mobile appliaction w android week 1 by osama
Python week 1 2020-2021
6 css week12 2020 2021 for g10
Css week11 2020 2021 for g10 by eng.osama ghandour
Cooding history
Computer networks--network
How to print a sketch up drawing in 3d
Google sketch up-tutorial
7 types of presentation styles on line
Design pseudo codeweek 6 2019 -2020
Php introduction
Ad

Recently uploaded (20)

PDF
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
PPTX
Renaissance Architecture: A Journey from Faith to Humanism
PDF
Complications of Minimal Access Surgery at WLH
PDF
STATICS OF THE RIGID BODIES Hibbelers.pdf
PPTX
Institutional Correction lecture only . . .
PPTX
Cell Structure & Organelles in detailed.
PDF
Supply Chain Operations Speaking Notes -ICLT Program
PPTX
Final Presentation General Medicine 03-08-2024.pptx
PDF
O5-L3 Freight Transport Ops (International) V1.pdf
PDF
Classroom Observation Tools for Teachers
PPTX
human mycosis Human fungal infections are called human mycosis..pptx
PDF
102 student loan defaulters named and shamed – Is someone you know on the list?
PPTX
master seminar digital applications in india
PPTX
PPH.pptx obstetrics and gynecology in nursing
PDF
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPTX
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
PPTX
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
PDF
2.FourierTransform-ShortQuestionswithAnswers.pdf
PDF
01-Introduction-to-Information-Management.pdf
PDF
VCE English Exam - Section C Student Revision Booklet
Saundersa Comprehensive Review for the NCLEX-RN Examination.pdf
Renaissance Architecture: A Journey from Faith to Humanism
Complications of Minimal Access Surgery at WLH
STATICS OF THE RIGID BODIES Hibbelers.pdf
Institutional Correction lecture only . . .
Cell Structure & Organelles in detailed.
Supply Chain Operations Speaking Notes -ICLT Program
Final Presentation General Medicine 03-08-2024.pptx
O5-L3 Freight Transport Ops (International) V1.pdf
Classroom Observation Tools for Teachers
human mycosis Human fungal infections are called human mycosis..pptx
102 student loan defaulters named and shamed – Is someone you know on the list?
master seminar digital applications in india
PPH.pptx obstetrics and gynecology in nursing
ANTIBIOTICS.pptx.pdf………………… xxxxxxxxxxxxx
PPT- ENG7_QUARTER1_LESSON1_WEEK1. IMAGERY -DESCRIPTIONS pptx.pptx
1st Inaugural Professorial Lecture held on 19th February 2020 (Governance and...
2.FourierTransform-ShortQuestionswithAnswers.pdf
01-Introduction-to-Information-Management.pdf
VCE English Exam - Section C Student Revision Booklet

Week2 ch4 part1edited 2020

  • 1. Agenda 1- Warm up Listen to this video about motivating programmers 5 min 2- ppt teacher demonstrate about loops 20 min 3- Video about how we can use c programming in rea life projects , automation and solving problems 3 min 4-Students play or act a game about simulating loops 10 min 5- practical work using lap tops through code blocks i implement a small program work in pairs 10 min 6- use netacade.com to self learn C and get certificate from CISCO 5 min 7- Questions and answers 20 min 8-Refelection 5 min 9- Home work
  • 2. LO CS.2.02 - Design programs involving decision structures and loops. Lesson plan
  • 3. Warm Up Listen to this video motivating programmers Open Code blocks or www.Jdoodle.com on line
  • 4. Essential Question 1- why we use computers ? 2- what are the tasks , jobs which can be computerized ? 3- what are Repetitions or loops 4- Distinguish between while and do while and for loop
  • 5. Warm Up Listen to this video Off line On line
  • 6. Essential Question How to Perform certain repetitive tasks , control all loops by sequence statements?
  • 8. 8 Repetition Statements • Repetition statements allow us to execute a statement or a block of statements multiple times • Like conditional statements, they are controlled by boolean expressions • C has three kinds of repetition statements: while Do while for
  • 9. Types of Loops • Pretest - a logical condition is checked before each repetition to determine if the loop should terminate –while loop –for loop • Posttest - a logical condition is checked after each repetition for termination –do-while loop
  • 10. PreTest vs. PostTest Loops Pretest Loop Condition Action or Actions true f alse Posttest Loop Condition Action or Actions true f alse
  • 11. 11 The while Statement • A while statement has the following syntax: • If the condition is true, the statement is executed • Then the condition is evaluated again, and if it is still true, the statement is executed again • The statement is executed repeatedly until the condition becomes false while ( condition ) statement;
  • 12. Logic of a while Loop statement true false condition evaluated 5
  • 13. 13 The while Statement • An example of a while statement: • If the condition of a while loop is false initially, the statement is never executed • Therefore, the body of a while loop will execute zero or more times int count = 0; while (count < 2) { printf("Welcome to C programming!"); count++; }
  • 14. Trace while Loop int count = 0; while (count < 2) { printf("Welcome to C programming!"); count++; } Initialize count animation 7
  • 15. Trace while Loop, cont. int count = 0; while (count < 2) { printf("Welcome to C programming!"); count++; } (count < 2) is true animation 8
  • 16. Trace while Loop, cont. int count = 0; while (count < 2) { printf("Welcome to C programming!"); count++; } Print Welcome to Java animation 9
  • 17. Trace while Loop, cont. int count = 0; while (count < 2) { printf("Welcome to C programming!"); count++; } Increase count by 1 count is 1 now animation 10
  • 18. Trace while Loop, cont. int count = 0; while (count < 2) { printf("Welcome to C programming!"); count++; } (count < 2) is still true since count is 1 animation 11
  • 19. Trace while Loop, cont. int count = 0; while (count < 2) { printf("Welcome to C programming!"); count++; } Print Welcome to C programming animation 12
  • 20. Trace while Loop, cont. int count = 0; while (count < 2) { printf("Welcome to C programming!"); count++; } Increase count by 1 count is 2 now animation 13
  • 21. Trace while Loop, cont. int count = 0; while (count < 2) { printf("Welcome to C programming!"); count++; } (count < 2) is false since count is 2 now animation 14
  • 22. Trace while Loop int count = 0; while (count < 2) { System.out.println("Welcome to Java!"); count++; } The loop exits. Execute the next statement after the loop. animation 15
  • 23. Posttest Loop: Do-While Syntax: do { statement(s) } while (condition); Corresponds to: statement if (!condition) DONE statement if (!condition) DONE ... condition statement(s) true f alse
  • 24. Using the Do-While do { printf(“Enter id# and salary: “); scanf(“%d %f”,&id,&salary); printf(“You entered id#%1d and salary $%.2f, Is this correct? (Y/N) “ ,id,salary); scanf(“ %c”,&ans); } while (!((ans == ‘Y’) || (ans == ‘y’))); • Loop always executes at least once
  • 25. While vs Do-While • Differences –where condition tested: • while (first) - may execute 0 times • do-while (last) - must execute at least one time • Similarities –one statement executed –initialization before loop –update during loop
  • 26. Pretest Loop: For • Initialization included in loop header • Update included in loop header • Header also includes update • Syntax: for ( init ; condition ; update ) statement; • Generally for loops expected to execute fixed number of times (counter-controlled)
  • 27. For Loop • Syntax: for ( init ; condition ; update ) statement; • Init: assignments to counter variables • Update: changes to counter variables Condition Statement true f alse Init Update
  • 28. For Example • Printing vertical line of stars: for (counter = 0; counter < 5; counter++) printf(“*n”); counter < 5 printf ("*n"); true f alse counter = 0; counter++;
  • 29. For Example - Sum of 1 to N printf(“Number to sum to: “); scanf(“%d”,&N); total = 0; for (I = 1; I <= N; I++) total += I; /* total is now 1 + 2 + … + N */
  • 30. Are we ready to code it? http://www.stemassiut.info prepared By Mr. Osama Ghandour 30
  • 33. For Example - Max of N Scores printf(“Number of students: “); scanf(“%d”,&NumStudents); for (I = 0; I < NumStudents; I++) { printf(“Enter student score %d: “); scanf(“%d”,&score); if (score > max) max = score; } /* max is highest score entered */
  • 34. Listen to this video about programming Arduino Off line On line
  • 35. Directions of Counting for (I = 10; I >= 1; I--) printf(“%d…n”,I); printf(“0 BLASTOFF!n”); printf(“Enter start, end, inc values: “); scanf(“%d%d%d”,&lstart,&lend,&linc); for (I = lstart; ((linc < 0) && (I < lend)) || ((linc > 0) && (I > lend)); I += linc) printf(“%dn”,I);
  • 36. practical work using lap tops through code blocks in implement a C small program work in pairs 20 min
  • 37. Use netacade.com to self learn C and get certificate from CISCO 7 7 min
  • 39. 39 –While –Do while –For Repetition Statements / Loops Types of loops : Summary
  • 40. Reflection • What is your goal to accomplish in next week End Using loops in C programming Language ?
  • 42. students create in small groups a c program related to their capstone project . Home work + = C program Arduino Arduino hardware controller components of irradiation system
  • 43. Home Work Discuss how to use Loops in coding different programs in a video by using office mix. 43
  • 44. Resources • watch a video that explain different ways for loops and read in the following links : https://www.youtube.com/watch?v=Rtww8 3GH0BU 44

Editor's Notes

  • #42: But don’t hide behind your slides.
  • #46: And practice, practice, practice.