# Java to Python: Incrementation within "if" statement

**URL:** <https://discourse.processing.org/t/java-to-python-incrementation-within-if-statement/5655>\
**Category:** Processing.py\
**Created:** [November 18, 2018, 1:32am UTC](https://discourse.processing.org/t/java-to-python-incrementation-within-if-statement/5655 "2018-11-18T01:32:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [November 18, 2018, 1:32am UTC](https://discourse.processing.org/t/java-to-python-incrementation-within-if-statement/5655/1 "2018-11-18T01:32:09Z")

</div>

Hi,

I was just wondering how you would convert that snippet to Python ?

```auto
for(int i=0; i<space.length; i++){
      int k=0;
      while(numCubes<space[i]){
        ...
        if((k++)>100){

          done = 1;

```

I’m not sure how to convert the `if((k++)>100` part.

```auto
for i in range(len(space)):
    k = 0
    while numCubes < space[i];
        k += 1
        ...
        if k > 100:
            done = 1

```

Does that make sense ?

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 18, 2018, 1:45am UTC](https://discourse.processing.org/t/java-to-python-incrementation-within-if-statement/5655/2 "2018-11-18T01:45:18Z")

</div>

> [@solub](#):
>
> `if (k++ > 100) {`

- That’s the postfix version of the unary increment operator `++`.
- Like its counterpart prefix version, it also increments the value stored in a variable by `1`.
- However, the postfix version still evaluates as the original previous value instead!
- As a workaround for Python, you can increment variable _k_ after the `if () {}` block:

```python
if k > 100:
    # ...

k += 1

```

---

<div class="post-metadata">

**Author:** ![solub](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/solub/32/333_2.png) [@solub](https://discourse.processing.org/u/solub)\
**Post date:** [November 18, 2018, 1:49am UTC](https://discourse.processing.org/t/java-to-python-incrementation-within-if-statement/5655/3 "2018-11-18T01:49:40Z")

</div>

Sweet !

PS: Happy Birthday to you GoToLoop. Thank you for your valuable and continual help. Have a great day.

---

<div class="post-metadata">

**Author:** ![GoToLoop](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/gotoloop/32/86_2.png) [@GoToLoop](https://discourse.processing.org/u/GoToLoop)\
**Post date:** [November 18, 2018, 1:51am UTC](https://discourse.processing.org/t/java-to-python-incrementation-within-if-statement/5655/4 "2018-11-18T01:51:55Z")

</div>

Oh, thx! 🥳
