حلقات التكرار.

Slides:



Advertisements
Similar presentations
Looping Structures: Do Loops
Advertisements

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.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
Do/Loops A loop repeats a series of instructions. An iteration is a single execution of the statement(s) in the loop. Used when the exact number of iterations.
Slide 1 VB Program Flow Control. Slide 2 Making Decisions v Decision Statement: control the execution of parts of the program based on conditions. v The.
Loops Counting down from N to 1 in assembly we used JUMP statements to repeat previous instructions thus looping READ LOOP: WRITE SUB decrement JPOSLOOP.
Iteration (Looping Constructs in VB) Iteration: Groups of statements which are repeatedly executed until a certain test is satisfied Carrying out Iteration.
1 Principles of Software Design and Development LOOPS / REPITITION.
Repetition Statements Repeating an Action A specified number of times While a Condition is True Until a Condition is True.
CIS 115 Lecture 8. There are 3 control structures common to most computer languages that determine the flow, or path of execution, of the code:  Sequential.
1 CC111 Lec9 : Visual Basic Visual Basic (3) Lecture 9.
Chapter 6 - VB 2005 by Schneider1 Chapter 6 – Repetition 6.1 Do While and Do Until Loops 6.2 Processing Lists of Data with Do Loops 6.3 For...Next Loops.
ENGR 112 Decision Structures.
Comparing and ordering rational numbers
Loops ISYS 350. A Box of Chocolate Repeat this process until box is empty: – Take one chocolate from the box – Eat the chocolate – Box has more chocolate?
CSCI 3327 Visual Basic Chapter 4: Control Statements in Visual Basic (Part 2) UTPA – Fall 2011 Part of the slides is from Dr. John Abraham’s previous.
1 Week 6 The Repetition Structure. 2 The Repetition Structure (Looping) Lesson A Objectives After completing this lesson, you will be able to:  Code.
Compunet Corporation1 Programming with Visual Basic.NET While, Do and For – Next Loops Week 5 Tariq Ibn Aziz.
Statements That Repeat. For...Next Loop Structure For counter = start To end Step increment statements Next counter Where Counter is tested to see if.
CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.
Visual Basic Programming Making Decisions: Loops & Decision Structures ©Copyright by Ronald P. Kessler, Ph.D.
Tutorial 6 The Repetition Structure
Visual Basic.net Loops. Used to do multiple executions of the same block of code Do while loops Do until loops For next loops.
Saeed Ghanbartehrani Summer 2015 Lecture Notes #5: Programming Structures IE 212: Computational Methods for Industrial Engineering.
Loops ISYS 350. Compute the sum of a list of numbers: Example: 5, 2, 10, 8, 4 Process: Sum= 0 Get a number from the list Sum = Sum + the number Repeat.
6.2 For…Next Loops General Form of a For…Next Loop
Developing Software Applications Iteration in Visual Basic (Loops)
Repetition Structures
Copyright © 2001 by Wiley. All rights reserved. Chapter 6: Using Arrays Control Arrays List Arrays Finding Items in Arrays Multiple Forms 2-Dimensional.
Other Variable Types Dim lab as String makes a box that can store a label tag Dim ColHead As String ColHead = “function” ColHead function Dim lab as Boolean.
Looping Structures Do Loops, For Next Do...Loop While structures check the condition after executing the code and repeat a code block until the test.
Tutorial 6: The Repetition Structure1 Tutorial 6 The Repetition Structure.
For…Next and Do...While Loops! Happy St. Patrick’s Day!
CSC 162 Visual Basic I Programming. Repetition Structures Pretest Loop –Exit condition is tested before the body of code is executed Posttest Loop –Exit.
1 Microsoft® Visual Basic®.NET Language # 2. 2 Flow-Control Statements If … End If Select Case … End Select For… Next Do … Loop Exit.
Controlling Program Flow with Looping Structures
Lab 6 (1) Range Review, Control Logic and Loops ► Control Logic and Loops ► Exercise.
Sum of Arithmetic Sequences. Definitions Sequence Series.
Looping Structures. A B dialog box that pops up and prompts the user for input Text area that pops up and prompts the user for to wait while it gets.
CSET 3250 Client-Side Scripting VBScript : Operators, Control Structures, Procedures and Functions.
MIC305 Week 6 Beyond controls Review of properties Differences with VB6: using classes and instances Programming constructs.
1 VB-04-Control Structures 16 March 2016 Visual Basic Control Structures - Selection.
5a – While Loops Lingma Acheson Department of Computer and Information Science, IUPUI CSCI N331 VB.NET Programming.
Dani Vainstein1 VBScript Session 5. Dani Vainstein2 What we learn last session? Branching Branching using If … Then … Else statement. Branching using.
COMPUTER PROGRAMMING I 5.05 Apply Looping Structures.
Loops ISYS 350. Write a Program that asks user to enter any numbers and displays the largest number Process: Largest = the first number Get the next number.
Chapter 6 Controlling Program Flow with Looping Structures.
CE En 270 Brigham Young University Norm Jones
Follow up from lab See Magic8Ball.java Issues that you ran into.
Tutorial 10 – Class Average Application Introducing the Do…Loop While and Do…Loop Until Repetition Statements Outline Test-Driving the Class Average.
3rd prep. – 2nd Term MOE Book Questions.
3rd prep. – 2nd Term MOE Book Questions.
Introducing Do While & Do Until Loops & Repetition Statements
الاسباب الأضرار وسائل الحمايه
Chapter 6 – Repetition 6.1 Do Loops 6.2 For...Next Loops
البرمجة بلغة فيجول بيسيك
مراحل كتابة البرنامج بلغة فيجول بيسك ستديو
مراجعة الحاسب.
CPS120: Introduction to Computer Science
البرمجة بلغة الفيجول بيسك ستوديو
البرمجة بلغة فيجول بيسك ستوديو
Comparing and Ordering Rational Numbers
Chapter (3) - Looping Questions.
2-1 Inductive Reasoning.
Loops ISYS 350.
Visual Basic Programming
Dictionary Builder Part 1 Getting Started.
Conditional Loops Counted Loops
Final Revision sheet- term2
Final Revision sheet- term2
Presentation transcript:

حلقات التكرار

ماهي أدوات المخرجات & المدخلات . .... لطباعة النتيجة ماهي أدوات المخرجات & المدخلات . .... لطباعة النتيجة المدخلات: textbox inputbox المخرجات : label listbox msgbox متى تستخدم الاداة ListBox - هي واحدة من الأدوات التي ترتبط غالباً بالتكرار وتتيح لك هذه الأداة أن تنشئ أو تعرض قائمة من العناصر وان تختار منها .

قاعدة(For…Next): نقوم بتكرار مجموعة من العمليات بعدد محدد من المرات. حلقات التكرار من أهم القواعد في لغات البرمجة إمكانية تكرار عدد من الخطوات عدداً من المرات... من حلقات التكرار.. قاعدة(For…Next): نقوم بتكرار مجموعة من العمليات بعدد محدد من المرات. قاعدة(Do While): تستمر حلقة التكرار ما دام الشرط صحيحاً. قاعدة(Do Until): تستمر حلقة التكرار ما دام الشرط خاطئاً.

For … next

قاعدة For… Next For Counter = Start To End [Step step] بداية صيغة القاعدة القيمة النهائية للعدّاد For Counter = Start To End [Step step] .................. [Exit For] ................... Next القيمة الأولية للعدّاد مقدار الزيادة لدورة التكرار وهي اختيارية إذا لم تحدد فأن الزيادة الأفتراضبة هي القيمة (1) عدد مرات التكرار يسمى عداّد (متغير من نوع عدد صحيح) نهاية حلقة التكرار ليعود التنفيذ إلى جملة (For) من جديد اختيارية تستخدم عندما نريد الخروج من التكرار عند شرط معين حتى لو لم تنته حلقة التكرار

نريد طباعة الأعداد (من 1 إلى 10) تصاعديا :- مثال نريد طباعة الأعداد (من 1 إلى 10) تصاعديا :- Dim m As Integer For m = 1 To 10 ListBox1.Items.Add(m) Next

نريد طباعة الأعداد (من 10 إلى 1) تنازليا:- مثال نريد طباعة الأعداد (من 10 إلى 1) تنازليا:- Dim m As Integer For m = 10 To 1 Step -1 MsgBox(m) Next

MsgBox(m & “استغفر الله” ) Next مثال باستخدام For…Next اكتبي كود يقوم بتكرار عبارة "استغفر الله" 10 مرات في الأداةMsgBox كما هو ظاهر أمامك في النموذج علماً بأن الحلقة تبدا من (1-10) Dim m As Integer For m = 1 To 10 MsgBox(m & “استغفر الله” ) Next

Do while

قاعدة DO WHILE في كل مرة يصل البرنامج إلي Do While يقوم بتقييم الشرط. أ- لو كان الشرط خاطئاً "False" فإن التنفيذ يبدأ عند أول أمر بعد كلمة Loop ب-لو كان الشرط صحيحا "True" فإن الحاسب يقوم بتنفيذ الأوامر ابتداء من الأمر الذي يلي الشرط وحتى أخر أمر قبل كلمة Loop وعندما يصل البرنامج إلي كلمة Loop فإنه يعود مرة أخري إلي Do while حيث يتم تقييم الشرط مرة أخري وطبقا لقيمة الشرط فإما أن تكون True فيستمر التكرار أو تكون False فينتهي التكرار .

Do While condition statement .................. [Exit Do] loop بداية صيغة القاعدة Do While condition statement .................. [Exit Do] loop الشرط الذي سيتم التكرار بناءً عليه ما دام الشرط صحيحا اختيارية وتستخدم للخروج من التكرار عند شرط معين حتى لو لم يتحقق الشرط الذي سيتم التكرار بناءً عليه. نهاية حلقة التكرار ليعود التنفيذ إلى جملة (Do) من جديد

Dim M As Integer =1 Do While M<=10 MsgBox(M) M=M+1 Loop مثال برنامج يطبع الأعداد من 1 إلى 10 :- Dim M As Integer =1 Do While M<=10 MsgBox(M) M=M+1 Loop

مثال من 25 الى 55

الامر Do…. Loop While & طريقه كتابه اخرى.. يعمل الأمر Do …. Loop While مثل الأمر Do While .. Loop مع اختلاف بسيط ,, وهو أن الشرط يتم تقييمه بعد نهاية كل تكرار وليس قبل بدايته وهذا يؤدي إلي أن الأوامر التي ستتكرر سيتم تنفيذها على الأقل مرة واحدة بعكس Do While .. Loop حيث أن الأوامر قد لا يتم تنفيذها علي الإطلاق .

مثال

Do until

قاعدة DO until علي العكس من Do While….. Loop فان Do Until ….. Loop يختبر الشرط فإذا كان خاطئاً False يبدأ التكرار ويستمر حتى يصبح الشرط صحيحاً True وعندها يتوقف التكرار والشرط الموجود في البناء Do Until …….. Loop يسمى شرط إنهاء التكرار .

Do Until condition statement .................. [Exit Do] loop بداية صيغة القاعدة Do Until condition statement .................. [Exit Do] loop الشرط الذي سيتم التكرار بناءً عليه ما دام الشرط خاطئاً اختيارية وتستخدم للخروج من التكرار عند شرط معين حتى لو لم يتحقق الشرط الذي سيتم التكرار بناءً عليه. نهاية حلقة التكرار ليعود التنفيذ إلى جملة (Do) من جديد

مثال

الامر Do…. Loop until& طريقه كتابه اخرى.. نفس أوجه الشبة وأوجه الاختلاف بين Do While.. Loop و Do Until .. Loop موجود أيضا بين Do …. Loop While و Do …. Loop Until .

مثال