Logic: AND, OR, NOT · المنطق: AND, OR, NOT
A club that checks your age
- A coding club takes members only from age 11 to 16. One test cannot say both ends.
ANDisTRUEonly when both tests areTRUE.- Write the variable on each side:
Age >= 11 AND Age <= 16.
A club that checks your age (نادي يتحقق من عمرك)
- نادٍ برمجية يقبل الأعضاء فقط من عمر 11 إلى 16. اختبار واحد لا يمكن أن يقول كلا الطرفين.
ANDهوTRUEفقط عندما يكون both (كلا) الاختبارينTRUE.- اكتب المتغير على كل جانب:
Age >= 11 AND Age <= 16.
DECLARE Age : INTEGER
Age ← 14
IF Age >= 11 AND Age <= 16
THEN
OUTPUT "accepted"
ELSE
OUTPUT "no"
ENDIF
OR: either test is enough
- A bus fare is free for a child or a senior: under 5, or 65 and over.
ORisTRUEwhen at least one test isTRUE.
OR: either test is enough (OR: أي اختبار يكفي)
- تذاكر الحافلة مجانية للطفل أو لكبير السن: أقل من 5، أو أكبر من 65 وأكبر منها.
ORهوTRUEعندما يكون على الأقل اختبار واحدTRUE.
DECLARE Age : INTEGER
Age ← 70
IF Age < 5 OR Age >= 65
THEN
OUTPUT "free"
ELSE
OUTPUT "pay"
ENDIF
NOT flips a Boolean
NOTturnsTRUEintoFALSE, andFALSEintoTRUE.- A search that has not found the target yet is
NOT Found.
NOT يعكس القيمة المنطقية
NOTيحولTRUEإلىFALSE، وFALSEإلىTRUE.- بحث لم يجد الهدف بعد هو
NOT Found.
DECLARE Found : BOOLEAN
Found ← FALSE
IF NOT Found
THEN
OUTPUT "missing"
ENDIF
Watch out
Mark >= 0 AND <= 100is not a test. The second half has nothing to compare.- Parentheses make a mix obvious:
NOT (Age < 11 OR Age > 16).
انتبه
Mark >= 0 AND <= 100ليس اختباراً. النصف الثاني ليس لديه ما يقارن به.- الأقواس تجعل المزيج واضحاً:
NOT (Age < 11 OR Age > 16).
Common mistakes
AND,ORandNOTare keywords. Their operands areBOOLEAN, usually from a relational test.9618putsTHENon theIFline. This course keepsTHENon the next line.
أخطاء شائعة
AND،ORوNOTكلمات مفتاحية. مؤثراتها هيBOOLEAN، عادة من اختبار علاقي.9618يضعTHENعلى السطرIF. هذا المسار ي keepsTHENفي السطر التالي.
Now you try
- Each task is one decision. Write both sides of
ANDand ofOR. - Press Check answer to test it.
الآن جرب بنفسك
- كل مهمة هي قرار واحد. اكتب كلا طرفي
ANDوOR. - اضغط على تحقق من الإجابة لاختبارها.
Read an INTEGER Age. Output accepted when it is from 11 to 16 inclusive, using AND. Otherwise output no. · اقرأ رقمًا صحيحًا INTEGER Age. أخرج accepted عندما يكون من 11 إلى 16 متضمنًا، باستخدام AND. وإلا أخرج no.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
Read an INTEGER Age. Output free when Age is under 5 or at least 65, using OR. Otherwise output pay. · اقرأ رقمًا صحيحًا INTEGER Age. أخرج free عندما يكون Age أقل من 5 أو على الأقل 65، باستخدام OR. وإلا أخرج pay.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
Found is a BOOLEAN set to FALSE. If NOT Found, output missing. · Found ملف BOOLEAN مُعدّ لـ FALSE. إذا NOT Found، أخرج missing.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.