What does the loop for ((i=0;i<5;++i)); do echo $i; done print?

Study for the OSCP Linux Exam. Use our flashcards and multiple-choice questions to test your skills. Each query comes with detailed hints and explanations to enhance your preparedness. Get ready to conquer the exam!

Multiple Choice

What does the loop for ((i=0;i<5;++i)); do echo $i; done print?

Explanation:
This uses a C-style for loop in Bash. It starts with i=0, checks i<5 before each iteration, and after each iteration runs the increment ++i. The body prints the current value of i. Since the increment happens after the body, the values seen and printed are 0, 1, 2, 3, 4. When i becomes 5, the condition i<5 is false, so the loop stops. Echo prints each value on its own line, giving 0 through 4, each on a new line.

This uses a C-style for loop in Bash. It starts with i=0, checks i<5 before each iteration, and after each iteration runs the increment ++i. The body prints the current value of i. Since the increment happens after the body, the values seen and printed are 0, 1, 2, 3, 4. When i becomes 5, the condition i<5 is false, so the loop stops. Echo prints each value on its own line, giving 0 through 4, each on a new line.

Subscribe

Get the latest from Passetra

You can unsubscribe at any time. Read our privacy policy