حلقة
هيكل حلقة
while في لغة البرمجة جافا تُستخدم لتنفيذ كتلة من الأوامر مرارًا وتكرارًا طالما يظل الشرط المُعطى صحيحًا. تتكون حلقة while من شرط واحد فقط يُقيّم قبل كل تكرار للحلقة.هيكل حلقة
while يبدو كالتالي:while (condition) {
// الأوامر التي يتم تنفيذها إذا كان الشرط صحيحًا
}
إليك مثال بسيط على استخدام حلقة while في جافا:int i = 0;في هذا المثال، ستتكرر الحلقة
while (i < 5) {
System.out.println("Iteration number: " + i);
i++;
}
while طالما كانت قيمة i أقل من 5. في كل تكرار، يتم طباعة الرسالة ومن ثم زيادة قيمة i بواحد. عندما تصبح قيمة i مساوية لـ 5، يصبح الشرط غير صحيح وتتوقف الحلقة عن التكرار.❤1👍1
حلقة
هيكل حلقة
do-while في جافا هي حلقة تكرار تضمن تنفيذ الكود داخل الحلقة مرة واحدة على الأقل، حتى إذا كان الشرط غير صحيح من البداية. بعد التنفيذ الأول للأوامر داخل الحلقة، يتم التحقق من الشرط: إذا كان صحيحًا، يتم تكرار الحلقة مرة أخرى، وهكذا دواليك حتى يصبح الشرط غير صحيح.هيكل حلقة
do-while في جافا:do {
// الأوامر التي ستُنفذ
} while (condition);
مثال بسيط على استخدام حلقة do-while:int i = 0;في هذا المثال، تبدأ الحلقة بتنفيذ الأوامر داخل الكتلة
do {
System.out.println("Iteration number: " + i);
i++;
} while (i < 5);
do. ثم تُقيّم الحالة في الجزء while. طالما أن الشرط (i < 5) صحيح، ستستمر الحلقة في التكرار.❤1👍1
👍3👎1
#java_1
A switch can only test for equality using the equality operator (==).
A switch can only test for equality using the equality operator (==).
Anonymous Quiz
61%
True
39%
False
#java_1
Used to break out of a loop if a certain condition is met.
Used to break out of a loop if a certain condition is met.
Anonymous Quiz
79%
break
21%
Continue
#java_1
Will stop further execution of the current iteration of a loop, and then evaluate the LCC and continue if it is true.
Will stop further execution of the current iteration of a loop, and then evaluate the LCC and continue if it is true.
Anonymous Quiz
22%
break
78%
Continue
#java_1
a syntax to select one of many code blocks to be executed
a syntax to select one of many code blocks to be executed
Anonymous Quiz
26%
if else
12%
if
40%
switch
22%
loop
#java_1
A ... statement tests a variable for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.
A ... statement tests a variable for equality against a list of values. Each value is called a case, and the variable being switched on is checked for each case.
Anonymous Quiz
14%
if else
67%
switch
11%
for loop
8%
Do while
The while loop repeats a set of code while the condition is not met?
Anonymous Quiz
44%
True
56%
False
What is true about a break?
Anonymous Quiz
31%
Break forces the control out of the loop and starts the execution of next iteration
9%
Break halts the execution of the loop for certain time frame
39%
Break halts the execution and forces the control out of the loop
21%
Break stops the execution of entire program
Which of the following is not a decision making statement?
Anonymous Quiz
14%
if
7%
if-else
25%
switch
54%
do-while
The while loop repeats a set of code while the condition is not met?
Anonymous Quiz
38%
True
62%
False
🤩1
What is true about a break?
Anonymous Quiz
30%
Break forces the control out of the loop and starts the execution of next iteration
12%
Break halts the execution of the loop for certain time frame
41%
Break halts the execution and forces the control out of the loop
18%
Break stops the execution of entire program
Which of the following is not a decision making statement?
Anonymous Quiz
11%
if
8%
if-else
28%
switch
54%
do-while
👍1
What is the range of short data type in Java?
#java_1
#java_1
Anonymous Quiz
37%
-128 to 127
30%
-32768 to 32767
6%
-2147483648 to 2147483647
27%
None of the mentioned
What is the range of byte data type in Java?
#java_1
#java_1
Anonymous Quiz
63%
-128 to 127
11%
-32768 to 32767
11%
-2147483648 to 2147483647
15%
None of the mentioned