الحلقات التكرارية وجمل الدوران (loops)

Slides:



Advertisements
Similar presentations
IHE Cardiology. IHE Cardiology Page 2 Problem Statement
Advertisements

Repetition Statements Perform the same task repeatedly Allow the computer to do the tedious, boring things.
For(int i = 1; i
February 12, 2013 COMP Introduction to Programming For Statement and More Loops Haohan Li TR 11:00 – 12:15, SN 011 Spring 2013.
Do-while Loops Programming. COMP102 Prog Fundamentals I: do-while Loops /Slide 2 The do-while Statement l Syntax do action while (condition) l How it.
Do/while Structure (L15) * do/while structure * break Statement * continue Statement * Loop Programming Techniques - Interactive input within a loop -
1 10/20/08CS150 Introduction to Computer Science 1 do/while and Nested Loops Section 5.5 & 5.11.
1 10/11/06CS150 Introduction to Computer Science 1 do/while and Nested Loops.
COMP102 – Programming Fundamentals I LA2B (Mon 5-7pm) LA2E (Fri 3-5pm) LA2F (Fri 5-7pm) TA: Jackie Lo.
CS Data Structures Appendix 1 How to transfer a simple loop- expression to a recursive function (factorial calculation)
ECE122 L11: For loops and Arrays March 8, 2007 ECE 122 Engineering Problem Solving with Java Lecture 11 For Loops and Arrays.
Repetition Structures: For Loop Constants CSC 1401: Introduction to Programming with Java Week 5 Wanda M. Kunkle.
Repetition Structures: Do-while Loop Random Number Generation CSC 1401: Introduction to Programming with Java Week 6 Wanda M. Kunkle.
Computer Programming 1 Repetition. Computer Programming 2 Objectives Repetition structures Study while and do loops Examine for loops A practical example.
Loops Programming. COMP104 Lecture 9 / Slide 2 Shortcut Assignment l C++ has a set of operators for applying an operation to a variable and then storing.
For Loops Programming. COMP102 Prog Fundamentals I: for Loops/Slide 2 The for Statement condition action true false initialization update.
1 Principles of Software Design and Development LOOPS / REPITITION.
Examples from “c++ how to program” book. SELECTIONS WITH IF-ELSE Example: if ( grade >= 60) cout = 60) cout
Control Structures Session 03 Mata kuliah: M0874 – Programming II Tahun: 2010.
Chapter 5 Control Structures: Loops 5.1 The while Loop The while loop is probably the most frequently used loop construct. The while loop is a conditional.
CSCI 3328 Object Oriented Programming in C# Chapter 5: C# Control Statement – Part II UTPA – Fall
Programming in Java Unit 4. Learning outcome:  LO2: Be able to design Java solutions  LO3: Be able to implement Java solutions Assessment criteria:
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
Chapter 7 LOOPING OPERATIONS: ITERATION. Chapter 7 The Flow of the while Loop.
LOOPS In the Name of Allah The Most Merciful The Most Compassionate LOOPS
While Loops Programming. COMP102 Prog Fundamentals I: while Loops/Slide 2 Shortcut Assignments l C++ has a set of shortcut operators for applying an operation.
GAME102 - INTRO WHILE LOOPS G. MacKay. Fundamental Control Structures  STRAIGHT LINE  CONDITIONAL  LOOPS.
Repetition Structures Repetition Structures allow you to write programs that will repeat program steps multiple times. –Also called Loops –Counter controlled.
1 Chap 4. Data Should know Declare & Initialize variables Declare constants Assignment Operators Increment and Decrement Operators Precedence of Operators.
Adding 10 items to a list… lstTest.Items.Add(1) lstTest.Items.Add(2) lstTest.Items.Add(3) lstTest.Items.Add(4) lstTest.Items.Add(5) lstTest.Items.Add(6)
The For Repetition Structure. Syntax for (initial-expression1, conditional-expression2, loop-expression3) { statement(s); } Example: for (int counter=1;
ITERATIVE STATEMENTS. Definition Iterative statements (loops) allow a set of instruction to be executed or performed several until condition are met.
Chapter 15 JavaScript: Part III The Web Warrior Guide to Web Design Technologies.
 for loop  while loop  do-while loop for (begin point; end point ; incrementation ) { //statements to be repeated }
Introduction to Computing Concepts Note Set 15. JOptionPane.showMessageDialog Message Dialog Allows you to give a brief message to the user Can be used.
 In computer programming, a loop is a sequence of instruction s that is continually repeated until a certain condition is reached.  PHP Loops :  In.
1 Chapter 3: Loops and Logic. 2 Control Statements If statement Example NumberCheck.java Relational operators (, >=, ==, !=) Using code blocks with If.
Copyright © 2012 Pearson Education, Inc. Chapter 5: Loops.
Chapter 9 Control Structures.
COMP 110 More loops Luv Kohli September 15, 2008 MWF 2-2:50 pm Sitterson
Source Page US:official&tbm=isch&tbnid=Mli6kxZ3HfiCRM:&imgrefurl=
Loops Tonga Institute of Higher Education. Introduction Programs need to be able to execute tasks repeatedly. Use loops to repeat actions  For Loop 
Путешествуй со мной и узнаешь, где я сегодня побывал.
Loops causes program to execute the certain block of code repeatedly until some conditions are satisfied. Suppose you want to execute some code/s 10 times.
LESSON 5 Loop Control Structure. Loop Control Structure  Operation made over and over again.  Iterate statement.
Sentinel Loops. while Syntax while(expression) statement.
Loops A loop is: Java provides three forms for explicit loops:
Chapter 9 Repetition.
Unit-1 Introduction to Java
Intro to Programming Week # 6 Repetition Structure Lecture # 10
CiS 260: App Dev I Chapter 4: Control Structures II.
Programming Fundamentals
Topics discussed in this section:
Loops in C C has three loop statements: the while, the for, and the do…while. The first two are pretest loops, and the the third is a post-test loop. We.
Page 1. Page 2 Page 3 Page 4 Page 5 Page 6 Page 7.
Chapter 5 Repetition.
CS149D Elements of Computer Science
Repetition Statements
For & do/while Loops.
الكلية الجامعية للعلوم التطبيقية
CSC115 Introduction to Computer Programming
Chapter 9 Control Structures.
Example Problems for Exam#2 (covers chapters 5, 6, 7, 8, 9)
Structured Program Development in C
Welcome back to Software Development!
for, do-while and switch statments
JavaScript: Control Statements II
do/while Selection Structure
PROGRAM FLOWCHART Iteration Statements.
Lec 6 Loop Statements Introduction to Computer Programming
Presentation transcript:

الحلقات التكرارية وجمل الدوران (loops) الكلية الجامعية للعلوم التطبيقية لغة برمجة حديثة (1) COMP 2301 د.سناء الصايغ الفصل الأول 2010- 2011 الحلقات التكرارية وجمل الدوران (loops)

الحلقات التكرارية وجمل الدوران المحتويات الحلقات التكرارية وجمل الدوران (Loops) for loop while loop do...while loop  Page 2

الحلقات التكرارية وجمل الدوران Control Statements الحلقات التكرارية وجمل الدوران الحلقات التكرارية وجمل الدوران تستخدم الحلقات التكرارية او جمل الدوران فى كل لغات الحاسوب لتساهم فى أداء العمليات التى تتكرر فى البرنامج وهى تتضمن شروطاً معينة لبدء وانتهاء العملية المتكررة. وتحتوى لغة الجافا على ما يلي من الحلقات التكرارية: حلقة for التكرارية. حلقة While التكرارية. حلقة Do …. While التكرارية.  Page 3 3

الحلقات التكرارية وجمل الدوران Control Statements الحلقات التكرارية وجمل الدوران حلقة for التكرارية تستخدم الحلقة for لتكرار عملية معينة عددًا من المرات باستخدام عدّاد وفقا للصيغة التالية: حيث: counter: متغير العداد. start_value: القيمة الابتدائية للعداد. criteria: نطاق الشروط، وهو شرط متغير العداد اللازم تحققه لاستمرار الحلقة التكرارية. increment: زيادة او انقاص قيمة العداد بقيمة معينة. for ( counter = start_value ; criteria ; increment ) { statement 1; statement 2; }  Page 4 4

الحلقات التكرارية وجمل الدوران Control Statements الحلقات التكرارية وجمل الدوران حلقة for التكرارية مثال على استخدام حلقة for هذا المثال يقوم بطباعة الأرقام من (1 – 10) على الشاشة يبدأ العداد عند قيمة (n=1) ويقوم بطباعة اول جملة (قيمة العداد في هذا المثال) ومن ثم يقوم بزيادة قيمة العداد بمقدار 1، ومن ثم يقوم بعملية التحقق من الشرط وتكرار العملية الى ان تصبح قيمة العداد = 10 for ( n = 1; n <= 10; n++ ) {     System.out.println(n); }  Page 5 5

الحلقات التكرارية وجمل الدوران Control Statements الحلقات التكرارية وجمل الدوران تمرين 1: قم بكتابة برنامج يطلب من المستخدم إدخال قيمة عددية ثم قم بطباعة الأرقام من 1 الى القيمة المدخلة باستخدام جملة for.  Page 6 6

الحلقات التكرارية وجمل الدوران Control Statements الحلقات التكرارية وجمل الدوران حلقة whileالتكرارية تستخدم حلقة while لتكرار عملية او اكثر طالما بقي الشرط متحققا. وتتبع الصيغة التالية: حيث: condition: شرط استمرار الحلقية التكرارية. statement: العبارة المراد تكرارها. while ( condition ) { statement 1; statement 2; }  Page 7 7

الحلقات التكرارية وجمل الدوران Control Statements الحلقات التكرارية وجمل الدوران حلقة for التكرارية مثال على استخدام حلقة while هذا المثال يقوم بطباعة الأرقام من (1 – 10) تقوم جملة while بفحص الشرط ثم تقوم بطباعة قيمة العداد ثم زيادة قيمة العداد بمقدار 1 int n = 1; while ( n <= 10 ) {     System.out.println(n); n++; }  Page 8 8

الحلقات التكرارية وجمل الدوران Control Statements الحلقات التكرارية وجمل الدوران تمرين 2: قم بكتابة برنامج يطلب من المستخدم إدخال قيمة عددية ثم قم بطباعة الأرقام من 1 الى القيمة المدخلة باستخدام جملة while.  Page 9 9

الحلقات التكرارية وجمل الدوران Control Statements الحلقات التكرارية وجمل الدوران حلقة do…while التكرارية هذه الحلقة تشبه الحلقة while ولكن في هذه الحالة يأتي فحص الشرط بعد تنفيذ العبارات المراد تكرارها. (ما الفارق في ذلك؟) حيث: condition: شرط استمرار الحلقية التكرارية. statement: العبارة المراد تكرارها. do{ statement 1; statement 2; } while ( condition ) ;  Page 10 10

الحلقات التكرارية وجمل الدوران Control Statements الحلقات التكرارية وجمل الدوران حلقة for التكرارية مثال على استخدام حلقة do…while هذا المثال يقوم بطباعة الأرقام من (1 – 10) تقوم جملة do…while بطباعة قيمة العداد ثم تقوم بزيادة قيمة العداد بمقدار 1 ثم تقوم بفحص الشرط int n = 1; {     System.out.println(n); n++; } while ( n <= 10 );  Page 11 11

الحلقات التكرارية وجمل الدوران Control Statements الحلقات التكرارية وجمل الدوران تمرين 3: قم بكتابة برنامج يطلب من المستخدم إدخال قيمة عددية ثم قم بطباعة الأرقام من 1 الى القيمة المدخلة باستخدام جملة do…while.  Page 12 12