> For the complete documentation index, see [llms.txt](https://www.pranaypourkar.co.in/the-programmers-guide/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://www.pranaypourkar.co.in/the-programmers-guide/java/java-basics/java-operators/problems.md).

# Problems

## 1. Operators

Why both print same values?

```java
for (i = 0;i<10;i++) {
  System.out.print(i);
}
System.out.println();
for (i=0;i<10;++i) {
  System.out.print(i);
}

// 0123456789
// 0123456789
```

Both `i++` and `++i` **increment the value of `i` by 1**, but the **difference lies in when the increment happens** in expressions — **not in loops like `for` where the value isn't used during increment.**

{% hint style="success" %}

* `i++` → **Post-increment**: Increments `i` after the value is used
* `++i` → **Pre-increment**: Increments `i` before the value is used
  {% endhint %}

But in a `for` loop:

```java
for (i = 0; i < 10; i++)  // or ++i
```

The **increment expression (`i++` or `++i`) happens after each iteration**, and its return value is **not used anywhere** in the loop control itself.

So both loops behave the same:

1. Initialize `i = 0`
2. Check condition `i < 10`
3. Execute `System.out.print(i)`
4. Increment `i` (post or pre — doesn’t matter because value isn't used)
5. Repeat

If we wrote something like:

```java
int x = i++;
int y = ++i;
```

Here, the difference matters:

* `x = i++`: assigns the value of `i` to `x`, **then increments** `i`
* `y = ++i`: increments `i`, **then assigns** the new value to `y`


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## 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, and the optional `goal` query parameter:

```
GET https://www.pranaypourkar.co.in/the-programmers-guide/java/java-basics/java-operators/problems.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

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.
