נבנה על ידיBuilt by Ariel Yohimovich
age >= 18.condition: A yes-or-no question the program checks, like age >= 18.true או false:boolean expression: An expression whose value is true or false:&& אם הצד השמאלי false, Java לא בודקת את הימני (התשובה כבר ידועה).short-circuit: With &&, if the left side is false Java doesn't check the right (the answer is already known).switch שבו כל case כתוב עם ->:switch expression: A switch where every case uses ->:true.Java checks the conditions top to bottom and runs only the first branch whose condition is true.else תופס את כל השאר.else catches everything else.true. else תופס את כל השאר.Java checks the conditions top to bottom and runs only the first branch whose condition is true. else catches everything else.int score = 82;
if (score >= 90) {
System.out.println("A");
} else if (score >= 80) {
System.out.println("B");
} else {
System.out.println("C");
}
System.out.println("סוף");int score = 82;
if (score >= 90) {
System.out.println("A");
} else if (score >= 80) {
System.out.println("B");
} else {
System.out.println("C");
}
System.out.println("Done");int score = 82;
if (score >= 90) {
System.out.println("A");
} else if (score >= 80) {
System.out.println("B");
} else {
System.out.println("C");
}
System.out.println("סוף");int score = 82;
if (score >= 90) {
System.out.println("A");
} else if (score >= 80) {
System.out.println("B");
} else {
System.out.println("C");
}
System.out.println("Done");B סוף
B Done
== שווה, != שונה, < <= > >=.== equal, != not equal, < <= > >=.&& וגם, || או, ! לא.Joiners: && and, || or, ! not.&& אם הצד הראשון false, השני לא נבדק בכלל (קיצור דרך (short-circuit)).With &&, if the first side is false the second isn't even checked (short-circuit).== שווה, != שונה, < <= > >=. מחברים: && וגם, || או, ! לא. ב-&& אם הצד הראשון false, השני לא נבדק בכלל (קיצור דרך (short-circuit)).== equal, != not equal, < <= > >=. Joiners: && and, || or, ! not. With &&, if the first side is false the second isn't even checked (short-circuit).case עם -> מריץ רק את עצמו (בלי break), אפשר לשים כמה ערכים בשורה, ואפשר לשמור את התוצאה במשתנה.In the new switch each case with -> runs only itself (no break), several values can share a line, and the result can go into a variable.default לכל השאר.default for everything else.case עם -> מריץ רק את עצמו (בלי break), אפשר לשים כמה ערכים בשורה, ואפשר לשמור את התוצאה במשתנה. default לכל השאר.In the new switch each case with -> runs only itself (no break), several values can share a line, and the result can go into a variable. default for everything else.int day = 6;
String kind = switch (day) {
case 1, 2, 3, 4, 5 -> "יום חול";
case 6, 7 -> "סוף שבוע";
default -> "?";
};
System.out.println(kind);int day = 6;
String kind = switch (day) {
case 1, 2, 3, 4, 5 -> "weekday";
case 6, 7 -> "weekend";
default -> "?";
};
System.out.println(kind);int day = 6;
String kind = switch (day) {
case 1, 2, 3, 4, 5 -> "יום חול";
case 6, 7 -> "סוף שבוע";
default -> "?";
};
System.out.println(kind);int day = 6;
String kind = switch (day) {
case 1, 2, 3, 4, 5 -> "weekday";
case 6, 7 -> "weekend";
default -> "?";
};
System.out.println(kind);סוף שבוע
weekend
yield.When a switch branch needs several lines, open a block and hand back the value with yield.yield. ל-if קצר שמחזיר ערך יש את האופרטור הטרנרי: תנאי ? אם כן : אם לא.When a switch branch needs several lines, open a block and hand back the value with yield. For a short if that returns a value there's the ternary operator: condition ? if yes : if no.int stars (כאן 4). בעזרת switch עם חצים, תרגמו ל-Masterpiece (5), Great (4), Good (3), Meh (1 או 2), ואחרת No rating. הדפיסו Rating: Great. אם stars מחוץ ל-1–5, הדפיסו לפני כן Invalid stars! (השתמשו ב-if).A book has int stars (here 4). With an arrow switch translate it to Masterpiece (5), Great (4), Good (3), Meh (1 or 2), otherwise No rating. Print Rating: Great. If stars is outside 1–5, first print Invalid stars! (use an if).age >= 18.condition: A yes-or-no question the program checks, like age >= 18.true או false:boolean expression: An expression whose value is true or false:&& אם הצד השמאלי false, Java לא בודקת את הימני (התשובה כבר ידועה).short-circuit: With &&, if the left side is false Java doesn't check the right (the answer is already known).switch שבו כל case כתוב עם ->:switch expression: A switch where every case uses ->:true.Java checks the conditions top to bottom and runs only the first branch whose condition is true.else תופס את כל השאר.else catches everything else.== שווה, != שונה, < <= > >=.== equal, != not equal, < <= > >=.&& וגם, || או, ! לא.Joiners: && and, || or, ! not.&& אם הצד הראשון false, השני לא נבדק בכלל (קיצור דרך (short-circuit)).With &&, if the first side is false the second isn't even checked (short-circuit).case עם -> מריץ רק את עצמו (בלי break), אפשר לשים כמה ערכים בשורה, ואפשר לשמור את התוצאה במשתנה.In the new switch each case with -> runs only itself (no break), several values can share a line, and the result can go into a variable.default לכל השאר.default for everything else.yield.When a switch branch needs several lines, open a block and hand back the value with yield.bigbigbig ואז mediumbig then mediummediummediumbigbig5 > 3 && 2 > 4?What is 5 > 3 && 2 > 4?truetruefalsefalse55falsefalse2 > 4 הוא false.Right: 2 > 4 is false.case 1 -> ... מ-case 1: ...?What's the main difference between case 1 -> ... and case 1: ...?n שימו 17.Put 17 in n.score שימו 73.Put 73 in score.age >= 18.condition: A yes-or-no question the program checks, like age >= 18.true.Java checks the conditions top to bottom and runs only the first branch whose condition is true.== שווה, != שונה, < <= > >=.== equal, != not equal, < <= > >=.case עם -> מריץ רק את עצמו (בלי break), אפשר לשים כמה ערכים בשורה, ואפשר לשמור את התוצאה במשתנה.In the new switch each case with -> runs only itself (no break), several values can share a line, and the result can go into a variable.yield.When a switch branch needs several lines, open a block and hand back the value with yield.נבנה על ידיBuilt by Ariel Yohimovich