شرح الجمل الشرطية في البرمجة

Choose a study mode

Play Quiz
Study Flashcards
Spaced Repetition
Chat to Lesson

Podcast

Play an AI-generated podcast conversation about this lesson
Download our mobile app to listen on the go
Get App

Questions and Answers

ما هي الوظيفة الرئيسية للجمل الشرطية في البرمجة؟

  • إجراء العمليات الحسابية
  • تحديد نوع المتغيرات
  • التحكم في مسار تنفيذ البرنامج بناءً على شروط معينة (correct)
  • تعريف الدوال

متى يتم تنفيذ الأوامر الموجودة داخل كتلة if؟

  • عندما يكون الشرط `false`
  • دائماً
  • عندما يكون الشرط `true` (correct)
  • عند تعريف المتغيرات

ماذا يحدث إذا كان هناك جملة if بدون else وكان الشرط false؟

  • يتم تنفيذ كتلة `if`
  • يتوقف البرنامج عن العمل
  • يحدث خطأ في البرنامج
  • يتم تجاهل كتلة `if` ويستمر البرنامج في التنفيذ (correct)

أي من العبارات التالية تصف بشكل صحيح استخدام if...else؟

<p>لتنفيذ أوامر معينة في حالة تحقق شرط وأوامر أخرى في حالة عدم تحققه (A)</p>
Signup and view all the answers

ما الغرض من استخدام المعاملات المنطقية في جملة if؟

<p>لاختبار أكثر من شرط في وقت واحد (A)</p>
Signup and view all the answers

ما هي الجملة الشرطية المتداخلة؟

<p>جملة شرطية داخل جملة شرطية أخرى (D)</p>
Signup and view all the answers

ما هي وظيفة جملة switch؟

<p>اختبار قيمة متغير مقابل عدة قيم محتملة (B)</p>
Signup and view all the answers

في جملة switch، ما هي وظيفة الكلمة المفتاحية break؟

<p>إنهاء تنفيذ الجملة <code>switch</code> والخروج منها (D)</p>
Signup and view all the answers

في جملة switch، ما هي وظيفة الكلمة المفتاحية default؟

<p>تحديد التعليمات التي تنفذ إذا لم تتطابق أي حالة (B)</p>
Signup and view all the answers

أي أداة تستخدم لعرض قائمة خيارات للمستخدم لاختيار واحد منها فقط؟

<p>زر اختيار (C)</p>
Signup and view all the answers

أي أداة تستخدم لعرض قائمة خيارات للمستخدم لتحديد ما يريده منها؟

<p>مربع اختيار (A)</p>
Signup and view all the answers

ما هي وظيفة أداة مجموعة الأزرار؟

<p>تجميع أزرار الاختيار لجعلها مرتبطة بموضوع معين (B)</p>
Signup and view all the answers

ماذا يحدث عند استخدام عامل المساواة (=) مرة واحدة بدلاً من عامل المساواة (==) مرتين في جملة if؟

<p>يتم تخصيص قيمة للمتغير بدلاً من المقارنة. (D)</p>
Signup and view all the answers

إذا كان لدينا متغير رقمي باسم score، كيف نختبر ما إذا كانت قيمته أكبر من أو تساوي 60؟

<p><code>score &gt;= 60</code> (C)</p>
Signup and view all the answers

كيف نجمع بين شرطين باستخدام العامل المنطقي AND في جملة if؟

<p><code>if (condition1 &amp;&amp; condition2)</code> (C)</p>
Signup and view all the answers

ماذا تعني قيمة الخاصية True للخاصية Checked لمربع الاختيار؟

<p>مربع الاختيار نشط ومحدد (D)</p>
Signup and view all the answers

كيف نُعلن عن متغير نصي عام باسم userName؟

<p><code>string userName;</code> (A)</p>
Signup and view all the answers

ما الغرض من استخدام Parse؟

<p>تحويل البيانات النصية إلى رقمية (D)</p>
Signup and view all the answers

ما الغرض من استخدام الفئة Font؟

<p>تغيير خصائص الخط مثل الحجم والنوع (D)</p>
Signup and view all the answers

أي من العبارات التالية تستخدم بشكل صحيح للتحقق من أن قيمة المتغير password تساوي "Secret"؟

<p><code>if (password == &quot;Secret&quot;)</code> (B)</p>
Signup and view all the answers

أي مما يلي يُعتبر مثالاً لجملة if متداخلة بشكل صحيح؟

<p><code>if (condition1) { if (condition2) { ... } }</code> (A)</p>
Signup and view all the answers

في بيئة تطوير Windows Forms، أي عنصر تحكم يستخدم لتمكين المستخدم من تحديد خيار واحد من بين مجموعة خيارات مختلفة؟

<p>زر الاختيار (RadioButton) (A)</p>
Signup and view all the answers

في بيئة تطوير Windows Forms، أي عنصر تحكم يسمح للمستخدم بتحديد خيارات متعددة في الوقت نفسه؟

<p>مربع الاختيار (CheckBox) (D)</p>
Signup and view all the answers

ما هي الخاصية التي تحدد ما إذا كان عنصر التحكم متاحًا للاستخدام في بيئة تطوير Windows Forms؟

<p>ممكن (Enabled) (B)</p>
Signup and view all the answers

ما هي الخاصية التي تحدد ما إذا كان عنصر التحكم مرئيًا في بيئة تطوير Windows Forms؟

<p>مرئي (Visible) (C)</p>
Signup and view all the answers

ما هي وظيفة عنصر تحكم GroupBox في بيئة تطوير Windows Forms؟

<p>لتجميع عناصر التحكم ذات الصلة معًا (D)</p>
Signup and view all the answers

كيف تحدد لون خلفية عنصر تحكم مربع النص (TextBox) إلى الأحمر في بيئة تطوير Windows Forms؟

<p>TextBox1.BackColor = Color.Red (B)</p>
Signup and view all the answers

ما هو الغرض من الأسلوب ()ToUpper في بيئة تطوير Windows Forms؟

<p>لتحويل النص إلى أحرف كبيرة (A)</p>
Signup and view all the answers

ما هو الغرض من الأسلوب ()Clear في بيئة تطوير Windows Forms؟

<p>لمسح محتويات عنصر التحكم (A)</p>
Signup and view all the answers

كيف تقوم بتغيير حجم خط النص في مربع نص (TextBox) إلى 14 في بيئة تطوير Windows Forms؟

<p>TextBox1.Font.Size = 14 (D)</p>
Signup and view all the answers

باستخدام اي من الخصائص التالية يتم تحديد محاذاة النص داخل مربع النص TextBox؟

<p>TextAlign (A)</p>
Signup and view all the answers

لجعل النص في مربع النص يظهر بالخط Times New Roman وحجم الخط 16, ما هو الكود المطلوب؟

<p>textBox1.Font = new Font(&quot;Times New Roman&quot;, 16); (B)</p>
Signup and view all the answers

ما هي الخاصية المستخدمة لإضافة صورة كخلفية لزر الامر (Button)؟

<p>Image (A)</p>
Signup and view all the answers

عند برمجة تطبيق ويندوز، ما وظيفة الدالة ()Application.Exit؟

<p>إنهاء البرنامج (C)</p>
Signup and view all the answers

Flashcards

جملة if الشرطية

أداة لاختبار تحقق شرط معين لتنفيذ أمر أو أوامر.

جملة if...else

تستخدم لتحديد أمر أو أوامر للتنفيذ في حالة صحة المقارنة, وأوامر أخرى في حالة عدم صحتها.

أداة Checkbox

تستخدم لتمكين المستخدم من تنشيط أكثر من اختيار في نفس الوقت.

RadioButton الأداة

تستخدم لعرض عدة بدائل، ويختار المستخدم واحد فقط.

Signup and view all the flashcards

أداة GroupBox

تستخدم لتنظيم الأدوات على النموذج، ولجعل مجموعات الأزرار مستقلة بذاتها.

Signup and view all the flashcards

الخطوط Fonts

فصيلة أو فئة لها خصائصها ووسائلها.

Signup and view all the flashcards

الجمل الشرطية

تعتبر من أهم المواضيع البرمجية وكيفية استخدامها للتحكم بسير البرنامج, وأيضا اختيار الأدوات بين البدائل.

Signup and view all the flashcards

Condition

الشرط الذي يتم اختباره.

Signup and view all the flashcards

تعبير المقارنة

وظيفة برمجية يتم استخدامها للمقارنة و ينتج عنها قيمة صحيحة true أو قيمة خاطئة false.

Signup and view all the flashcards

جملة switch

تستخدم لاختبار تواجد قيمة معينة.

Signup and view all the flashcards

المعاملات المنطقية في جملة if

يتم استخدامها لعمل شروط مركبة أي أنه سيتم اتخاذ القرار بناءا على تحقق شرطين وليش شرط واحد.

Signup and view all the flashcards

جملة else

تستخدم في الحالات التي يكون لدينا فيها بديلين ونريد تنفيذ احدهما ان تحقق الشرط وتنفيذ البديل ان لم يتحقق الشرظ.

Signup and view all the flashcards

الجملة الشرطية المتداخلة Nested if

تستخدم عند الحاجة إلى أكثر من شرط، وتكرر كلمة 'Else If' مهما كان عدد الشروط المطلوبة

Signup and view all the flashcards

FormBorderStyle

خاصية في الـ Form, تستخدم لجعل نافذة النموذج تشبه المربع الحواري عند عرضها.

Signup and view all the flashcards

ControlBox

خاصية في الـ Form , تستخدم لمنع ظهور المربع الذي يمكن من خلاله إغلاق النموذج في شريط العنوان.

Signup and view all the flashcards

المتغير orgtext

تستخدم لتخزين النص الأصلي قبل التعديل عليه في البرنامج.

Signup and view all the flashcards

Study Notes

Condition Statement (الجمل الشرطية)

  • This chapter discusses the conditional statements, which are one of the most important programming topics, and how to use them to control the program flow.
  • It also covers tools for choosing between alternatives.

Objectives

  • Explain the concept of conditional statements and their uses.
  • Write an if statement correctly to test whether a specific condition is true.
  • Write an if...else statement to execute specific commands if the condition is met and other commands if it is not met.
  • Apply logical operators to test more than one condition in an if statement.
  • Apply a nested if statement correctly.
  • Distinguish between using a simple if statement and a nested if statement.
  • Apply a switch statement to test for the presence of a specific value.
  • Use the radio button tool to display options for the user to select only one.
  • Test which button is activated from a group of buttons.
  • Use the checkbox tool to display options for the user to choose what they want from them.
  • Test the state of the checkbox (active or inactive).
  • Use the button group tool to use option buttons for more than one topic.
  • Use the font class to change font properties using code.

Conditional Statement

  • Conditional statements compare two values.
  • The value can be a variable with another value, or a property with another.
  • The conditional statement results in a (true) value if the comparison is correct, and (false) if the comparison is incorrect.

Example

  • If you designed an application to enter a student's grade in a test, and the passing grade in the test is (60) or more, and less than that is failing, if you want to determine whether the student is successful or failing, you must use a conditional statement that uses a comparison expression to test the grade, which we assume is stored in the variable Score.
  • Here, to determine whether the grade is greater than 60 or not, the formula is as follows: Score > 60

Examples of the results

  • If Score = 75, then the value of the previous comparison is True.
  • If Score = 59, then the value of the previous comparison is False.
  • In conditional statements, a command or commands are determined to be executed if the comparison is true, meaning it produces (True), and also a command or other commands are executed if the relationship is incorrect, meaning it produces (False).

The "if" Conditional Statement

  • This statement is used to test whether a specific condition (relationship) is true.
  • An order or set of orders is implemented if the condition is true.

General form of the statement

if (Condition)
{
Statements
}

Definition of terms

  • Condition: It is the condition that is tested.
    • As we mentioned, this condition is a comparison expression that results in either True or False.
    • The condition must be placed between ( ).
  • Statements: It is the command or set of commands that are executed if the condition is met, and these commands are placed between { }.

The Conditional "if...else" Statement

  • In the previous example, it is noted that when the value of the Score variable is greater than 60, a message appears to the user informing him of his success, but what if it is less? We did not tell him anything.
  • Therefore, you will find that there are situations in which we have two alternatives.
  • We want to implement one of them if the condition (True) is met, and implement the other alternative if the condition (False) is not met.

General form of if...else Statement

if (Condition)
{
    Statement Block 1
}
else
{
    Statement Block 2
}
  • Condition: The condition to be tested.
  • Statement Block 1: The order or orders to be implemented when the condition is met.
  • Statement Block 2: The order or orders to be implemented when the condition is not met.

Using Logical Operators in a Sentence

  • The logical operators can be used with an IF statement to create compound conditions.
  • That is, the decision will be made based on the verification of two conditions, not just one condition.
  • In such cases, it is called a compound condition because it consists of two or more conditions.

Nested Conditional Sentence "Nested if"

  • Sometimes you don't have only two alternatives (condition met or not met), but there are several alternatives, and each alternative has a set of commands that need to be executed.
  • In a program to calculate student grades and the grade of each student, there are multiple possibilities to calculate the grade based on the student's grade.
  • The option could be failing, acceptable, good, very good, or excellent.
  • This requires a new form of If that has multiple condition options

General form

if (Condition 1)
{
    Statements that are executed when the first condition is met
}
else if (Condition 2)
{
    Statements that are executed when the first condition is not met, and the second condition is met
}
else if (Condition 3)
{
    Statements that are executed when the first and second conditions are not met, and the third condition is met
}
else
{
    Statements that are executed when none of the previous conditions are met
}

Notes

  • The word Else If is repeated whenever there is a need to use a new condition until all the required conditions are finished, regardless of their number.
  • Each Else If is followed by several sentences that are executed when the condition is met.
  • The first condition is tested, and if it is met, the set of commands that follow it are executed, and then it exits the entire if statement to complete the rest of the program.
  • If the condition is not met, the next condition is tested, and if it is met, its commands are executed, and it exits from the if statement, and so on.
  • All conditions are tested until one of them is met, and if one of them is met, the rest of the conditions are not tested, but if no condition is met, the commands that follow the word else will be executed if it is used (where the position of else can be ignored).

Switch statement

  • When there are many possibilities that are expected to occur, or data that is likely to be entered, using an if statement becomes cumbersome to deal with therefore, if you expect at the evaluation of a certain condition many possibilities, switch statements are best.

General structure

switch (Condition)
{
  case Test value 1:
    Set of statements executed when the first possibility takes place
    break;
  case Test vaue 2:
    Set of statements executed when the second possibility takes place
    break;
  default:
    Set of statements executed if NO possibility takes places
    break;
}

Text description

  • Condition is the name of the element that will be tested and can be a variable or a class object, and it is written after the switch word between the ( ).
  • Test_value 1 is the first possibility for the value of the variable or expression, where the value follows the word case, and similarly Test_value 2 is the second possibility ....... etc.
  • You can test for the presence of several values, so the word case will be repeated several times depending on the number of values that need to be verified.
  • Each case is followed by a command or group of commands that are executed when the presence of the value is verified, provided that the last line contains the word break, which aims to exit the switch statement to execute the rest of the program's commands after { that belongs to it.
  • If the value in the first case is not met, it moves to the next case, then the third, and so on until the value is found; then the commands that follow it will be executed. - After executing the commands for the case that was met, the program continues after { .
  • The use of the word default is optional, where it is followed by a command or group of commands that are executed if no case of the cases is met.
  • If it is not written, if no value is found, none of the commands for the switch statement will be executed and the program will continue after {

Alternative Selection Tools

  • Often you want to display several alternatives to the user so that he chooses one of them.
  • For example, you display an option for him to activate or not activate, or you display several options for him to choose only one or more than one.

C#.NET provides 3 tools that are used to display several alternatives or options for the user to choose what suits his decision, namely

  • RadioButton Tool
  • This tool is used to display several alternatives (options) so that the user selects only one alternative from them.
  • Like any tool, click on it from the toolbox, then place it on the form.
  • The following table shows the basic properties of the tool.

Properties of RadialButtons

Name: To specify a name for the tool, usually beginning with "rad”. Appearance: For the appearance , where there are two choices, Normal or Button. Checked: Its value is True if the checkbox (button?) is active or its value is False if it is inactive.

GroupBox Tool

  • The GroupBox tool is used in the model for two purposes:
    • First: To organize the placement of the tools on the form.
    • By showing each group of buttons for a certain topic inside a rectangle, and then you can move these tools together by moving this rectangle.
    • Second: The tool is used if you have several RadioButtons on the model and you want to make each group of tools independent on its own. For instance, if you have a group button for the font color, and another group for the font size , if you place all the buttons then it is considered as a group button with connected importance, rather than each one being independent.

Studying That Suits You

Use AI to generate personalized quizzes and flashcards to suit your learning preferences.

Quiz Team

Related Documents

Condition Statements in C#

More Like This

Conditional Statements in Programming
24 questions

Conditional Statements in Programming

FascinatingCottonPlant4770 avatar
FascinatingCottonPlant4770
Conditional Statements and Loops
28 questions
Use Quizgecko on...
Browser
Browser