SlideShare una empresa de Scribd logo
1 de 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

Más contenido relacionado

La actualidad más candente

La actualidad más candente (20)

Queue
QueueQueue
Queue
 
Unit I-Data Structures_Intoduction.pptx
Unit I-Data Structures_Intoduction.pptxUnit I-Data Structures_Intoduction.pptx
Unit I-Data Structures_Intoduction.pptx
 
Data and time
Data and timeData and time
Data and time
 
Constructor,destructors cpp
Constructor,destructors cppConstructor,destructors cpp
Constructor,destructors cpp
 
Decorator Design Pattern
Decorator Design PatternDecorator Design Pattern
Decorator Design Pattern
 
Introduction to Data Structure
Introduction to Data Structure Introduction to Data Structure
Introduction to Data Structure
 
Unit 2 linked list
Unit 2   linked listUnit 2   linked list
Unit 2 linked list
 
C# classes objects
C#  classes objectsC#  classes objects
C# classes objects
 
Unsupervised Topic Modeling with BERTopic for Coarse and Fine-Grained News Cl...
Unsupervised Topic Modeling with BERTopic for Coarse and Fine-Grained News Cl...Unsupervised Topic Modeling with BERTopic for Coarse and Fine-Grained News Cl...
Unsupervised Topic Modeling with BERTopic for Coarse and Fine-Grained News Cl...
 
INLINE FUNCTION IN C++
INLINE FUNCTION IN C++INLINE FUNCTION IN C++
INLINE FUNCTION IN C++
 
Recursion in c++
Recursion in c++Recursion in c++
Recursion in c++
 
Intoduction to numpy
Intoduction to numpyIntoduction to numpy
Intoduction to numpy
 
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
Polymorphism in c++ ppt (Powerpoint) | Polymorphism in c++ with example ppt |...
 
functions in C and types
functions in C and typesfunctions in C and types
functions in C and types
 
JavaScript - Chapter 7 - Advanced Functions
 JavaScript - Chapter 7 - Advanced Functions JavaScript - Chapter 7 - Advanced Functions
JavaScript - Chapter 7 - Advanced Functions
 
Pandas
PandasPandas
Pandas
 
Python 3.x quick syntax guide
Python 3.x quick syntax guidePython 3.x quick syntax guide
Python 3.x quick syntax guide
 
arrays and pointers
arrays and pointersarrays and pointers
arrays and pointers
 
Unit 5 composite datatypes
Unit 5  composite datatypesUnit 5  composite datatypes
Unit 5 composite datatypes
 
Type casting
Type castingType casting
Type casting
 

Destacado

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
 

Destacado (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
 

Similar a 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
 

Similar a 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
 

Último

Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
AnaAcapella
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
QucHHunhnh
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
QucHHunhnh
 

Último (20)

Micro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdfMicro-Scholarship, What it is, How can it help me.pdf
Micro-Scholarship, What it is, How can it help me.pdf
 
Sociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning ExhibitSociology 101 Demonstration of Learning Exhibit
Sociology 101 Demonstration of Learning Exhibit
 
Spatium Project Simulation student brief
Spatium Project Simulation student briefSpatium Project Simulation student brief
Spatium Project Simulation student brief
 
On National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan FellowsOn National Teacher Day, meet the 2024-25 Kenan Fellows
On National Teacher Day, meet the 2024-25 Kenan Fellows
 
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Ữ Â...
 
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptxBasic Civil Engineering first year Notes- Chapter 4 Building.pptx
Basic Civil Engineering first year Notes- Chapter 4 Building.pptx
 
Dyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptxDyslexia AI Workshop for Slideshare.pptx
Dyslexia AI Workshop for Slideshare.pptx
 
Spellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please PractiseSpellings Wk 3 English CAPS CARES Please Practise
Spellings Wk 3 English CAPS CARES Please Practise
 
PROCESS RECORDING FORMAT.docx
PROCESS      RECORDING        FORMAT.docxPROCESS      RECORDING        FORMAT.docx
PROCESS RECORDING FORMAT.docx
 
Unit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptxUnit-V; Pricing (Pharma Marketing Management).pptx
Unit-V; Pricing (Pharma Marketing Management).pptx
 
General Principles of Intellectual Property: Concepts of Intellectual Proper...
General Principles of Intellectual Property: Concepts of Intellectual  Proper...General Principles of Intellectual Property: Concepts of Intellectual  Proper...
General Principles of Intellectual Property: Concepts of Intellectual Proper...
 
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
2024-NATIONAL-LEARNING-CAMP-AND-OTHER.pptx
 
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptxSKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
SKILL OF INTRODUCING THE LESSON MICRO SKILLS.pptx
 
Grant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy ConsultingGrant Readiness 101 TechSoup and Remy Consulting
Grant Readiness 101 TechSoup and Remy Consulting
 
1029 - Danh muc Sach Giao Khoa 10 . pdf
1029 -  Danh muc Sach Giao Khoa 10 . pdf1029 -  Danh muc Sach Giao Khoa 10 . pdf
1029 - Danh muc Sach Giao Khoa 10 . pdf
 
1029-Danh muc Sach Giao Khoa khoi 6.pdf
1029-Danh muc Sach Giao Khoa khoi  6.pdf1029-Danh muc Sach Giao Khoa khoi  6.pdf
1029-Danh muc Sach Giao Khoa khoi 6.pdf
 
Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...Making communications land - Are they received and understood as intended? we...
Making communications land - Are they received and understood as intended? we...
 
Holdier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdfHoldier Curriculum Vitae (April 2024).pdf
Holdier Curriculum Vitae (April 2024).pdf
 
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdfUGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
UGC NET Paper 1 Mathematical Reasoning & Aptitude.pdf
 
How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17How to Give a Domain for a Field in Odoo 17
How to Give a Domain for a Field in Odoo 17
 

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