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הופך ערך בוליאני. המשימות משתמשות בו על דגל (flag), ולא על מספר.
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אינו מבחן. - ב-IIGSE 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. · לחץ על הרץ כדי לראות את התוצא כאן.