File tree Expand file tree Collapse file tree 1 file changed +8
-0
lines changed
Expand file tree Collapse file tree 1 file changed +8
-0
lines changed Original file line number Diff line number Diff line change @@ -20,6 +20,14 @@ console.log(find("code your future", "z"));
2020// Pay particular attention to the following:
2121
2222// a) How the index variable updates during the call to find
23+ //The variable index starts at 0 and increases by 1 every time the loop runs (index++).
24+ //It keeps track of the current position in the string.
2325// b) What is the if statement used to check
26+ //The if statement checks whether the current character (str[index]) is equal to the one we’re searching for (char).
27+ //If it is, we immediately return index.
2428// c) Why is index++ being used?
29+ //It moves to the next character in the string during each loop iteration.
30+ //Without it, the loop would never move forward — it would keep checking the same character forever (infinite loop 🔁
2531// d) What is the condition index < str.length used for?
32+ //That’s the loop condition — it keeps the loop running as long as index is less than the length of the string.
33+ //Once index equals str.length, it means we’ve checked every character, and the loop stops.
You can’t perform that action at this time.
0 commit comments