# 09. Break and Continue MCQ

#### break/continue Question 1

```cpp
int a = 0, i = 0, b;
for (i = 0;i < 5; i++)
{
    a++;
    continue;
}

printf("%d", a);
```

<details>

<summary>Solution</summary>

There is no statement after `continue`. So its presence makes no difference. It would work just like a normal `for` loop.

The value of `a` and `i` changes similarly.

`a` value after the loop is its value at the last iteration i.e. when `i = 4`; loop breaks at `i = 5`. In the last iteration `a = 5`.

```
OUTPUT:
  5
```

</details>

#### break/continue Question 2

```cpp
int a = 0, i = 0, b;
for (i = 0;i < 5; i++)
{
  a++;
  if (i == 3)
    break;
}

print("%d", a);
```

<details>

<summary>Solution</summary>

The `for` loop runs until `i` is 3; after that it breaks out of the loop.

```
4
```

</details>

#### break/continue Question 3

```cpp
int i = 0, j = 0;
for (i = 0;i < 5; i++)
{
  for (j = 0;j < 4; j++)
    if (i > 1)
      break;
  printf("Hi \n");
}
```

<details>

<summary>Solution</summary>

The `i` loop runs for i in {0, 1, 2, 3, 4}. The `j` loops runs for j in {0, 1, 2, 3}. The loop doesn't impact how many times hi is printed.

The `break` statement only breaks the `j` loop which does not stops the `i` loop from printing "Hi".

So "Hi" is printed as many times as `i` loop runs; 5 times.

```
OUTPUT:
  Hi
  Hi
  Hi
  Hi
  Hi
```

</details>

#### break/continue Question 4

```cpp
int i = 0;
for (i = 0;i < 5; i++)
  if (i < 4)
  {
    printf("Hello");
    break;
  }
```

<details>

<summary>Solution</summary>

The `i` loop runs for i in {0, 1, 2, 3, 4}.

As soon as the `if` statement is `true`. It prints "Hello" and breaks out of the `i` loop.

The `if` statement is `true` in the first iteration i.e. `i = 0`.

So "Hello" is printed only once.

```
OUTPUT:
  Hello
```

</details>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://abhyas-kanaujia.gitbook.io/lb-dsa-notes-and-homework-abhyas/03-programming-basics-ii/homework/09.-break-and-continue-mcq.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
