Ask Question
30 August, 12:13

What is the output of the code below?

for (int j = 1; j < = 10; j++)

{

if (j = = 3)

{

break;

}

cout << j << endl;

}

Output:

for (int j = 1; j < = 10; j++)

{

if (j = = 3)

{

continue;

}

cout << j << endl;

}

Output:

Expert

+2
Answers (1)
  1. 30 August, 15:12
    0
    The first output for the following code is given below:

    1

    2

    The second output for the following code is given below

    1

    2

    4

    5

    6

    7

    8

    9

    10

    Explanation:

    In the first code the loop will iterated

    When j=1 the condition of if block will not be executed so it print 1 on console and increment the value of j.

    After increment of j it becomes 2 again if block does not executed because the condition of if block is not true so it print 2 on console and increased the value of j.

    When j=3 if condition block is executed and it terminate the loop immediately.

    Therefore output is:

    1

    2

    In the second code the loop will iterate

    When j=1 the condition of if block is not executed so it print 1 on console and increment the value of j.

    After increment the value of j it becomes 2. Again if block will not be executed so it print 2 on console and increased the value of j.

    After increment the value of j becomes 3. This time if block will executed, it will moved directly control to the beginning of the loop and skip the current execution of statements that means it skip the value j=3 and increment the value of j.

    Now j=4 this process is same follow untill when j<=10 when j=11 the loop is false and loop will terminate.

    Therefore output is:

    1

    2

    4

    5

    6

    7

    8

    9

    10
Know the Answer?
Not Sure About the Answer?
Get an answer to your question ✅ “What is the output of the code below? for (int j = 1; j < = 10; j++) { if (j = = 3) { break; } cout ...” in 📙 Computers & Technology if there is no answer or all answers are wrong, use a search bar and try to find the answer among similar questions.
Search for Other Answers