Decision Structures Introduction:-So far, our programs have been rather linear Most have executed single-path, unbranched computation: Make Declaration ?Get Input ?Apply a Process ? Output Result However, most real algorithms involve decision making. The ability to make decisions is called branching. Blocks of code for making decisions are called Decision Structures.VB .NET provides several flavors: f The If…Then statement f The If…Then…Else statement f The if ..Then..Elseif statement f The Select Case statement Each of these provides a means to control program flow via evaluation of one or more test conditions.Let’s take a look at the simplest: The If Statemen 1 عبارة if الشرطية العبارة الشرطية If تقوم بالتحكم بسير البرنامج بحيث بحسب شرط معين اذا تحقق يتم تنفيذ عبارة برمجية معينة والا يتم تنفيذ عبارة اخرى الصيغة العامة لها If (condition) then Statements or expressions to execute when the condition is true End if مثال-1- اكتب برنامج بلغة فجوال بيسك نت يقوم بكتابة ناجح (Pass) اذا كانت الدرجة اكبر او تساوي 50. ويكتب راسب (Fail) اذا كانت اقل 50. Private Sub btn_run_Click(sender As Object, e As EventArgs) Handles btn_run.Click Dim dgree As Integer dgree = InputBox("Enter The Value of degree")
If dgree < 50 Then MessageBox.Show("Fail") End If
If dgree >= 50 Then MessageBox.Show("Pass") End If
End Sub المخطط الانسيابي لعبارة if الشرطية
2 عبارة Else (والا) تستخدم كلمة else مع عبارة if الشرطية للتقليل من عدد عبارات if فبدلا ان نكتب If (conditions) then Statements or expressions to execute when the condition is true End if If (conditions) then Statements or expressions to execute when the condition is true End if يمكننا كتابتها كما يلي باستخدام Else ?
If (condition) then Statements or expressions to execute when the condition is true Else Statements or expressions to execute when the condition is false End If وبذلك تم اختصار عبارة if –Then End if كاملة المخطط الانسيابي ل if –Then -Else لهذا يمكن اعادة كتابة مثال -1- باستخدام عبارة Elseكمايلي:
? Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Run_btn.Click Dim dgree As Integer dgree = InputBox(“Enter The Value of degree”)
If dgree < 50 Then MessageBox.Show(“Fail”) Else MessageBox.Show(“Pass”) End If
End Sub
المادة المعروضة اعلاه هي مدخل الى المحاضرة المرفوعة بواسطة استاذ(ة) المادة . وقد تبدو لك غير متكاملة . حيث يضع استاذ المادة في بعض الاحيان فقط الجزء الاول من المحاضرة من اجل الاطلاع على ما ستقوم بتحميله لاحقا . في نظام التعليم الالكتروني نوفر هذه الخدمة لكي نبقيك على اطلاع حول محتوى الملف الذي ستقوم بتحميله .
|