While loops check a boolean condition before each iteration. When the condition is true, the loop body runs. When it becomes false, the loop stops.
Example: while (i < n && arr[i] != target) continues as long as you haven't reached the end AND haven't found the target. Either condition becoming false stops the loop.
For loops also use boolean conditions, though they're often hidden in the syntax. for (i = 0; i < n; i++) checks i < n before each iteration.