SlideShare ist ein Scribd-Unternehmen logo
1 von 16
Core Programming นายสมเกียรติ สอนนวล Cimatt Business Group Co.,LTD.
Core Programming Understand computerstorage and data types Understand computerdecision structures Identify the appropriatemethod for handlingrepetition Understand errorhandling
Identify the appropriatemethod for handlingrepetition Lesson Overview Students will identify the appropriate method for handling repetition. In this lesson, you will learn: for loops while loops do..while loops Recursion
Identify the appropriatemethod for handlingrepetition Iterations in Real Life  An iteration is the act of repeating a set of steps to perform a task. 		For example: Turn the screwdriver until the screw is tight. Rub my hands under the air dryer until they are dry. Iterations are modeled in computers. 		For example: (C#) for(int i = 0; i < 10; i++) Console.WriteLine(“I repeat ten times”);
Identify the appropriatemethod for handlingrepetition The while Loop Allows code to be repeated so long as a Boolean condition is met. The condition is evaluated before the code is executed. Can be used when the number of iterations is not known before executing the loop. inti = 0;			// Initialization while (i < 5)		// Condition { Console.WriteLine(i); i = i + 1;			// Increment }
Identify the appropriatemethod for handlingrepetition The for Loop Allows code to be repeated using a loop counter to control how many times it repeats. Used when the number of iterations is known before executing the loop. Initialization ConditionIncrement for (int i = 0; i < 5; i++) { Console.WriteLine(i); }
Identify the appropriatemethod for handlingrepetition while Loop vs. for Loop string line = "default"; while (line != "") { Console.Write("Enter a word (while):"); 	line = Console.ReadLine(); } Console.WriteLine(); for (int i = 0; i < 5; i++) { Console.Write("Enter a word (for) :"); line = Console.ReadLine(); }
Identify the appropriatemethod for handlingrepetition The do-while Loop Allows code to be repeated so long as a Boolean condition is met. The condition is evaluated after the code is already executed once. Can be used when the number of iterations is not known before string line = “default”; do { Console.WriteLine(“Enter a word:”); line = Console.ReadLine(); } while (line != null);
Identify the appropriatemethod for handlingrepetition while Loop vs. do-while Loop A do-while loop will execute at least once. A while loop might not execute at all. Console.WriteLine(“Enter a word:”); String line = Console.ReadLine(); while (line != null) { Console.WriteLine(“Enter a word:”); line = Console.ReadLine(); } do { Console.WriteLine(“Enter a word:”); line = Console.ReadLine(); } while (line != null)
Identify the appropriatemethod for handlingrepetition Counting from 1 to 10 with Different Loops for (int i = 1; i <= 10; i++) { Console.WriteLine(i); } inti = 1; while (i <= 10) { Console.WriteLine(i); i++; } inti = 1; do { Console.WriteLine(i); i++; } while (i <= 10);
Identify the appropriatemethod for handlingrepetition Scope Errors for(int i = 0; i < 5; i++) { Console.Writeline(i); } Console.WriteLine(i);  // syntax error // i is a local variable
Identify the appropriatemethod for handlingrepetition Recursion Recursion occurs when a method calls itself to solve another version of the same problem. With each recursive call, the problem becomes simpler and moves toward a base case. The base case is reached when no other recursive call is required. A base case is the point when no other recursive calls are made.
Identify the appropriatemethod for handlingrepetition Factorials public int fact(int n) { if (n == 1) 	return 1; else 	return n * fact(n - 1); } fact (4) 		24 fact (4) 4 * fact (3) 		6 fact (3) 3 * fact (2) 		2 fact (2) 2 * fact (1) 		1 fact (1)
Identify the appropriatemethod for handlingrepetition public int identity(int num) { if(num < 1) 	return 10; else 	return num + identity(num - 2); }
Assignment 1. Transform the following while loop into a for loop. int num = 1; while (num < 20) { Console.WriteLine(num); num = num + 1; } 2. Transform the following for loop into a while loop. for (int num = 1; num < 20; num = num+1) Console.WriteLine(num); 3. Transform the following while loop into a for loop int num = 10; while (num >= 0) { Console.WriteLine(num); num = num - 1; } 4. Whatoutput is produced by the following code? for (int x = 0; x < 3; x++) Console.WriteLine(x*3); 5.  How many lines of output will the following code produce? for (int x = 0; x < 13; x=x+2) Console.WriteLine(“line”);
Answer 1. 	for (int num = 1; num < 20; num = num+1) Console.WriteLine(num); 2.	int num = 1; 		while (num < 10) 		{ Console.WriteLine(num); 			num = num + 1; 		} 3.	 for (int num = 10; num >= 0; num = num-1) Console.WriteLine(num); 4.	0 		3 		6 5.	7

Weitere ähnliche Inhalte

Was ist angesagt?

Introduction à NetLogo
Introduction à NetLogoIntroduction à NetLogo
Introduction à NetLogo
Alvaro Gil
 
Exercices corrigés applications linéaires-djeddi kamel
Exercices corrigés applications linéaires-djeddi kamelExercices corrigés applications linéaires-djeddi kamel
Exercices corrigés applications linéaires-djeddi kamel
Kamel Djeddi
 
Correction de td poo n2
Correction de td poo n2Correction de td poo n2
Correction de td poo n2
yassine kchiri
 

Was ist angesagt? (20)

Chapitre 2 complexité
Chapitre 2 complexitéChapitre 2 complexité
Chapitre 2 complexité
 
Cours algorithme: structures répétitives
Cours algorithme: structures répétitivesCours algorithme: structures répétitives
Cours algorithme: structures répétitives
 
Examen principal - Fondement Multimedia - correction
Examen principal - Fondement Multimedia - correctionExamen principal - Fondement Multimedia - correction
Examen principal - Fondement Multimedia - correction
 
Curriculum informatique 2ème année Septembre 2019
Curriculum informatique 2ème année Septembre 2019Curriculum informatique 2ème année Septembre 2019
Curriculum informatique 2ème année Septembre 2019
 
Introduction à NetLogo
Introduction à NetLogoIntroduction à NetLogo
Introduction à NetLogo
 
Chapitre 03 : Structures de contrôle
Chapitre 03 : Structures de contrôleChapitre 03 : Structures de contrôle
Chapitre 03 : Structures de contrôle
 
Python avancé : Gestion d'erreurs et mécanisme d'exception
Python avancé : Gestion d'erreurs et mécanisme d'exceptionPython avancé : Gestion d'erreurs et mécanisme d'exception
Python avancé : Gestion d'erreurs et mécanisme d'exception
 
Exercices corrigés applications linéaires-djeddi kamel
Exercices corrigés applications linéaires-djeddi kamelExercices corrigés applications linéaires-djeddi kamel
Exercices corrigés applications linéaires-djeddi kamel
 
Chapitre 3 structures séquentielles
Chapitre 3 structures séquentiellesChapitre 3 structures séquentielles
Chapitre 3 structures séquentielles
 
Td dw1
Td dw1Td dw1
Td dw1
 
Fiche de TP 3 sur les bases de données avec les SGBD(Système de Gestion des B...
Fiche de TP 3 sur les bases de données avec les SGBD(Système de Gestion des B...Fiche de TP 3 sur les bases de données avec les SGBD(Système de Gestion des B...
Fiche de TP 3 sur les bases de données avec les SGBD(Système de Gestion des B...
 
TP C++ : Correction
TP C++ : CorrectionTP C++ : Correction
TP C++ : Correction
 
Correction de td poo n2
Correction de td poo n2Correction de td poo n2
Correction de td poo n2
 
Introduction à Python
Introduction à PythonIntroduction à Python
Introduction à Python
 
Cours complet Base de donne Bac
Cours complet Base de donne Bac Cours complet Base de donne Bac
Cours complet Base de donne Bac
 
Exercices_Python_Fenni_2023 -corrigé.pdf
Exercices_Python_Fenni_2023 -corrigé.pdfExercices_Python_Fenni_2023 -corrigé.pdf
Exercices_Python_Fenni_2023 -corrigé.pdf
 
TP N°1 sketchup.ppt
TP N°1 sketchup.pptTP N°1 sketchup.ppt
TP N°1 sketchup.ppt
 
Rtc
RtcRtc
Rtc
 
Exercice 1 java Héritage
Exercice 1 java HéritageExercice 1 java Héritage
Exercice 1 java Héritage
 
TD1-UML-correction
TD1-UML-correctionTD1-UML-correction
TD1-UML-correction
 

Andere mochten auch

1.1 core programming [understand computer storage and data types]
1.1 core programming [understand computer storage and data types]1.1 core programming [understand computer storage and data types]
1.1 core programming [understand computer storage and data types]
tototo147
 
1.2 core programming [understand computer decision structures]
1.2 core programming [understand computer decision structures]1.2 core programming [understand computer decision structures]
1.2 core programming [understand computer decision structures]
tototo147
 
1.4 core programming [understand error handling]
1.4 core programming [understand error handling]1.4 core programming [understand error handling]
1.4 core programming [understand error handling]
tototo147
 
Software Development Fundamentals
Software Development FundamentalsSoftware Development Fundamentals
Software Development Fundamentals
Chris Farrell
 
C Prog. - Operators and Expressions
C Prog. - Operators and ExpressionsC Prog. - Operators and Expressions
C Prog. - Operators and Expressions
vinay arora
 

Andere mochten auch (10)

1.1 core programming [understand computer storage and data types]
1.1 core programming [understand computer storage and data types]1.1 core programming [understand computer storage and data types]
1.1 core programming [understand computer storage and data types]
 
1.2 core programming [understand computer decision structures]
1.2 core programming [understand computer decision structures]1.2 core programming [understand computer decision structures]
1.2 core programming [understand computer decision structures]
 
1.4 core programming [understand error handling]
1.4 core programming [understand error handling]1.4 core programming [understand error handling]
1.4 core programming [understand error handling]
 
CPP03 - Repetition
CPP03 - RepetitionCPP03 - Repetition
CPP03 - Repetition
 
Software Development Fundamentals 1
Software Development Fundamentals 1Software Development Fundamentals 1
Software Development Fundamentals 1
 
Software Development Fundamentals
Software Development FundamentalsSoftware Development Fundamentals
Software Development Fundamentals
 
Presentation1
Presentation1Presentation1
Presentation1
 
Programming loop
Programming loopProgramming loop
Programming loop
 
C Prog. - Operators and Expressions
C Prog. - Operators and ExpressionsC Prog. - Operators and Expressions
C Prog. - Operators and Expressions
 
Operator in c programming
Operator in c programmingOperator in c programming
Operator in c programming
 

Ähnlich wie 1.3 core programming [identify the appropriate method for handling repetition]

C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
jahanullah
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
Vince Vo
 
C++ Loops General Discussion of Loops A loop is a.docx
C++ Loops  General Discussion of Loops A loop is a.docxC++ Loops  General Discussion of Loops A loop is a.docx
C++ Loops General Discussion of Loops A loop is a.docx
humphrieskalyn
 

Ähnlich wie 1.3 core programming [identify the appropriate method for handling repetition] (20)

Loops
LoopsLoops
Loops
 
06 Loops
06 Loops06 Loops
06 Loops
 
C Sharp Jn (3)
C Sharp Jn (3)C Sharp Jn (3)
C Sharp Jn (3)
 
06.Loops
06.Loops06.Loops
06.Loops
 
Loops (1)
Loops (1)Loops (1)
Loops (1)
 
CPP Homework Help
CPP Homework HelpCPP Homework Help
CPP Homework Help
 
Java căn bản - Chapter6
Java căn bản - Chapter6Java căn bản - Chapter6
Java căn bản - Chapter6
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Loops in c language
Loops in c languageLoops in c language
Loops in c language
 
Thread
ThreadThread
Thread
 
C++ Loops General Discussion of Loops A loop is a.docx
C++ Loops  General Discussion of Loops A loop is a.docxC++ Loops  General Discussion of Loops A loop is a.docx
C++ Loops General Discussion of Loops A loop is a.docx
 
Giorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrencyGiorgio zoppi cpp11concurrency
Giorgio zoppi cpp11concurrency
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02Claguage 110226222227-phpapp02
Claguage 110226222227-phpapp02
 
Control structures ii
Control structures ii Control structures ii
Control structures ii
 
while loop in C.pptx
while loop in C.pptxwhile loop in C.pptx
while loop in C.pptx
 
Object oriented programming system with C++
Object oriented programming system with C++Object oriented programming system with C++
Object oriented programming system with C++
 
Tdd with python unittest for embedded c
Tdd with python unittest for embedded cTdd with python unittest for embedded c
Tdd with python unittest for embedded c
 
C++ Course - Lesson 1
C++ Course - Lesson 1C++ Course - Lesson 1
C++ Course - Lesson 1
 
130707833146508191
130707833146508191130707833146508191
130707833146508191
 

Kürzlich hochgeladen

Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
KarakKing
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
heathfieldcps1
 

Kürzlich hochgeladen (20)

80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
80 ĐỀ THI THỬ TUYỂN SINH TIẾNG ANH VÀO 10 SỞ GD – ĐT THÀNH PHỐ HỒ CHÍ MINH NĂ...
 
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
TỔNG ÔN TẬP THI VÀO LỚP 10 MÔN TIẾNG ANH NĂM HỌC 2023 - 2024 CÓ ĐÁP ÁN (NGỮ Â...
 
Graduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - EnglishGraduate Outcomes Presentation Slides - English
Graduate Outcomes Presentation Slides - English
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Philosophy of china and it's charactistics
Philosophy of china and it's charactisticsPhilosophy of china and it's charactistics
Philosophy of china and it's charactistics
 
Salient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functionsSalient Features of India constitution especially power and functions
Salient Features of India constitution especially power and functions
 
Tatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf artsTatlong Kwento ni Lola basyang-1.pdf arts
Tatlong Kwento ni Lola basyang-1.pdf arts
 
latest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answerslatest AZ-104 Exam Questions and Answers
latest AZ-104 Exam Questions and Answers
 
Wellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptxWellbeing inclusion and digital dystopias.pptx
Wellbeing inclusion and digital dystopias.pptx
 
21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx21st_Century_Skills_Framework_Final_Presentation_2.pptx
21st_Century_Skills_Framework_Final_Presentation_2.pptx
 
Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)Accessible Digital Futures project (20/03/2024)
Accessible Digital Futures project (20/03/2024)
 
The basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptxThe basics of sentences session 3pptx.pptx
The basics of sentences session 3pptx.pptx
 
Single or Multiple melodic lines structure
Single or Multiple melodic lines structureSingle or Multiple melodic lines structure
Single or Multiple melodic lines structure
 
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptxOn_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
On_Translating_a_Tamil_Poem_by_A_K_Ramanujan.pptx
 
Plant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptxPlant propagation: Sexual and Asexual propapagation.pptx
Plant propagation: Sexual and Asexual propapagation.pptx
 
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptxExploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
Exploring_the_Narrative_Style_of_Amitav_Ghoshs_Gun_Island.pptx
 
SOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning PresentationSOC 101 Demonstration of Learning Presentation
SOC 101 Demonstration of Learning Presentation
 
Towards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptxTowards a code of practice for AI in AT.pptx
Towards a code of practice for AI in AT.pptx
 
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdfUnit 3 Emotional Intelligence and Spiritual Intelligence.pdf
Unit 3 Emotional Intelligence and Spiritual Intelligence.pdf
 
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptxHMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
HMCS Vancouver Pre-Deployment Brief - May 2024 (Web Version).pptx
 

1.3 core programming [identify the appropriate method for handling repetition]

  • 1. Core Programming นายสมเกียรติ สอนนวล Cimatt Business Group Co.,LTD.
  • 2. Core Programming Understand computerstorage and data types Understand computerdecision structures Identify the appropriatemethod for handlingrepetition Understand errorhandling
  • 3. Identify the appropriatemethod for handlingrepetition Lesson Overview Students will identify the appropriate method for handling repetition. In this lesson, you will learn: for loops while loops do..while loops Recursion
  • 4. Identify the appropriatemethod for handlingrepetition Iterations in Real Life An iteration is the act of repeating a set of steps to perform a task. For example: Turn the screwdriver until the screw is tight. Rub my hands under the air dryer until they are dry. Iterations are modeled in computers. For example: (C#) for(int i = 0; i < 10; i++) Console.WriteLine(“I repeat ten times”);
  • 5. Identify the appropriatemethod for handlingrepetition The while Loop Allows code to be repeated so long as a Boolean condition is met. The condition is evaluated before the code is executed. Can be used when the number of iterations is not known before executing the loop. inti = 0; // Initialization while (i < 5) // Condition { Console.WriteLine(i); i = i + 1; // Increment }
  • 6. Identify the appropriatemethod for handlingrepetition The for Loop Allows code to be repeated using a loop counter to control how many times it repeats. Used when the number of iterations is known before executing the loop. Initialization ConditionIncrement for (int i = 0; i < 5; i++) { Console.WriteLine(i); }
  • 7. Identify the appropriatemethod for handlingrepetition while Loop vs. for Loop string line = "default"; while (line != "") { Console.Write("Enter a word (while):"); line = Console.ReadLine(); } Console.WriteLine(); for (int i = 0; i < 5; i++) { Console.Write("Enter a word (for) :"); line = Console.ReadLine(); }
  • 8. Identify the appropriatemethod for handlingrepetition The do-while Loop Allows code to be repeated so long as a Boolean condition is met. The condition is evaluated after the code is already executed once. Can be used when the number of iterations is not known before string line = “default”; do { Console.WriteLine(“Enter a word:”); line = Console.ReadLine(); } while (line != null);
  • 9. Identify the appropriatemethod for handlingrepetition while Loop vs. do-while Loop A do-while loop will execute at least once. A while loop might not execute at all. Console.WriteLine(“Enter a word:”); String line = Console.ReadLine(); while (line != null) { Console.WriteLine(“Enter a word:”); line = Console.ReadLine(); } do { Console.WriteLine(“Enter a word:”); line = Console.ReadLine(); } while (line != null)
  • 10. Identify the appropriatemethod for handlingrepetition Counting from 1 to 10 with Different Loops for (int i = 1; i <= 10; i++) { Console.WriteLine(i); } inti = 1; while (i <= 10) { Console.WriteLine(i); i++; } inti = 1; do { Console.WriteLine(i); i++; } while (i <= 10);
  • 11. Identify the appropriatemethod for handlingrepetition Scope Errors for(int i = 0; i < 5; i++) { Console.Writeline(i); } Console.WriteLine(i); // syntax error // i is a local variable
  • 12. Identify the appropriatemethod for handlingrepetition Recursion Recursion occurs when a method calls itself to solve another version of the same problem. With each recursive call, the problem becomes simpler and moves toward a base case. The base case is reached when no other recursive call is required. A base case is the point when no other recursive calls are made.
  • 13. Identify the appropriatemethod for handlingrepetition Factorials public int fact(int n) { if (n == 1) return 1; else return n * fact(n - 1); } fact (4) 24 fact (4) 4 * fact (3) 6 fact (3) 3 * fact (2) 2 fact (2) 2 * fact (1) 1 fact (1)
  • 14. Identify the appropriatemethod for handlingrepetition public int identity(int num) { if(num < 1) return 10; else return num + identity(num - 2); }
  • 15. Assignment 1. Transform the following while loop into a for loop. int num = 1; while (num < 20) { Console.WriteLine(num); num = num + 1; } 2. Transform the following for loop into a while loop. for (int num = 1; num < 20; num = num+1) Console.WriteLine(num); 3. Transform the following while loop into a for loop int num = 10; while (num >= 0) { Console.WriteLine(num); num = num - 1; } 4. Whatoutput is produced by the following code? for (int x = 0; x < 3; x++) Console.WriteLine(x*3); 5. How many lines of output will the following code produce? for (int x = 0; x < 13; x=x+2) Console.WriteLine(“line”);
  • 16. Answer 1. for (int num = 1; num < 20; num = num+1) Console.WriteLine(num); 2. int num = 1; while (num < 10) { Console.WriteLine(num); num = num + 1; } 3. for (int num = 10; num >= 0; num = num-1) Console.WriteLine(num); 4. 0 3 6 5. 7