محاضرة 3
Arrays and Methods
المصفوفات وتعريف الدوال في Java.
يلا نشوف الملخص
📖 Lecture 3: Loops and Arrays (Derived from Activities and Tutorials)
- Loops: Used to execute a block of code multiple times.
- For Loop: Contains an initialization, condition, and increment/decrement. If a semicolon is placed immediately after the loop header (e.g.,
for(int i=0; i<5; i++);), the loop runs without executing any body block [12]. - Nested Loops: A loop inside another loop. The inner loop finishes all its iterations for every single iteration of the outer loop [12].
- For Loop: Contains an initialization, condition, and increment/decrement. If a semicolon is placed immediately after the loop header (e.g.,
- Loop Control:
break: Exits the loop entirely [12].continue: Skips the rest of the current iteration and jumps to the next iteration [12].
- Arrays: Used to store multiple values in a single variable (e.g.,
int[] arr = {10, 20, 30};) [12].- Array indexing always starts at
0[12]. - Attempting to access an index outside the array size (e.g.,
arr[12]in a 3-element array) causes anArrayIndexOutOfBoundsException[12, 13]. - Enhanced For-Loop: Iterates over arrays using a copy of the elements, meaning modifying the loop variable does not modify the original array [13].
- Array indexing always starts at
في نقطة مش واضحة؟ بطبط موجود!
اسأل بطبط عنها