Logic: AND, OR, NOT · المنطق: AND, OR, NOT
A club that checks both ends of the age
- A club takes members only from 11 to 16. One test cannot say both ends.
ANDisTRUEonly when both tests areTRUE:Age >= 11 AND Age <= 16.NOTflips a Boolean. The tasks use it on a flag, not on a number.
نادي يتحقق من طرفي العمر
- يقبل النادي أعضاءً فقط من 11 إلى 16. اختبار واحد لا يمكنه التحقق من الطرفين.
ANDهوTRUEفقط عندما يكون كلا الاختبارينTRUE:Age >= 11 AND Age <= 16.NOTيعكس القيمة المنطقية. المهام تستخدمه على علم إشارة، وليس رقماً.
DECLARE Age : INTEGER
Age ← 14
IF Age >= 11 AND Age <= 16 THEN
OUTPUT "accepted"
ELSE
OUTPUT "no"
ENDIF
A fare that depends on either age
- A bus fare is free under 5, or at 65 and over. One of those tests is enough.
ORisTRUEwhen either operand isTRUE.
رسوم تعتمد على أحد الطرفين
- رسوم الحافلة مجانية تحت سن 5، أو في سن 65 فما فوق. أحدهما يكفي.
ORهوTRUEعندما يكون أحد المعاملين على الأقلTRUE.
DECLARE Age : INTEGER
Age ← 70
IF Age < 5 OR Age >= 65 THEN
OUTPUT "free"
ELSE
OUTPUT "pay"
ENDIF
Nest the second decision
- 80 or more is a distinction. Otherwise, 50 or more is a pass, and the rest is a fail.
- The second
IFis the statement underELSE, with its ownENDIF. THENstays on theIFline, including the inner one.
تشابك القرار الثاني
- 80 فأكثر هو امتياز. وإلا، 50 فأكثر هو نجاح، والباقي رسوب.
IFالثاني هو التعليق الموجود تحتELSE، معENDIFخاص به.THENيبقى في السطرIF، بما في ذلك الداخلي.
DECLARE Mark : INTEGER
Mark ← 72
IF Mark >= 80 THEN
OUTPUT "Distinction"
ELSE
IF Mark >= 50 THEN
OUTPUT "Pass"
ELSE
OUTPUT "Fail"
ENDIF
ENDIF
Watch out
- Write the variable on both sides of
AND.Mark >= 0 AND <= 100is not a test. - IGCSE 0478 puts
THENon the following line. Do not mix the two papers.
انتبه
- اكتب المتغير على كلا طرفي
AND.Mark >= 0 AND <= 100ليس اختباراً. - IGCSE 0478 يضع
THENفي السطر التالي. لا تخلط بين الورقتين.
Common mistakes
ELSEbelongs to theIFabove it. Indent the innerIFso the finalENDIFis the outer one.NOTapplies to a Boolean.NOT Markis not how you test a number.
أخطاء شائعة
ELSEتابع لـIFالتي تعلوه. قم بإزاحةIFالداخلية مسافة بادئة بحيث يكونENDIFالنهائي هو الخارجي.NOTيُطبق على قيمة منطقية.NOT Markليست طريقة لاختبار رقم.
Now you try
- One task is an
OR, one is aNOT, and one is the nested grade.
الآن جرب بنفسك
- مهمة واحدة هي
OR، وأخرى هيNOT، والثالثة هي التصنيف المتشابك.
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. · اضغط تشغيل لرؤية المخرجات هنا.
Alarm is a BOOLEAN set to FALSE. If NOT Alarm, output quiet, otherwise output ring. · Alarm هو مجموعة BOOLEAN لـ FALSE. إذا NOT Alarm، أخرج quiet، وإلا أخرج ring.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.
Read an INTEGER Mark. Output Distinction for 80 or more, otherwise Pass for 50 or more, otherwise Fail. Put the second IF under ELSE, with THEN on the IF line. · اقرأ ⟨⟩ INTEGER Mark. اطبع Distinction إذا كانت القيمة 80 أو أكثر، وإلا اطبع Pass إذا كانت 50 أو أكثر، وإلا اطبع Fail. ضع الثاني ⟨⟩ IF تحت ELSE، مع وضع THEN في السطر IF.
Click Run to see the output here. · اضغط تشغيل لرؤية المخرجات هنا.