# Iteration counter

**URL:** <https://discourse.julialang.org/t/iteration-counter/122394>\
**Category:** New to Julia\
**Tags:** loops\
**Created:** [November 7, 2024, 8:33pm UTC](https://discourse.julialang.org/t/iteration-counter/122394 "2024-11-07T20:33:08Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![mary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mary/32/53139_2.png) [@mary](https://discourse.julialang.org/u/mary)\
**Post date:** [November 7, 2024, 8:33pm UTC](https://discourse.julialang.org/t/iteration-counter/122394/1 "2024-11-07T20:33:08Z")

</div>

Hi,  
I want to track the load steps in my code using gridap but i got operation cell field out of this code and I cant get the values. Is this way right to implement this? Also I added this print lines to check the process but I couldnt get any print notifications out of it.

```julia
function new_EnergyStateit(ψPlusPrev_in, ψhPos_in, current_step,last_update)
    ψPlus_in = ψhPos_in
    if ψPlus_in >= ψPlusPrev_in
        last_update = current_step
        println("Updated at step $current_step, last_update set to $last_update")
    else
        println("No update at step $current_step, last_update remains $last_update")
    end
    return last_update
end

```

I used this function as below

```julia
    update_steps = [] 
    last_update = 1.0 # Tracks the last update step

    while vApp <= vAppMax
        count = count + 1
         ψhPos_in = (ψPos∘(ε(uh)))
            current_step= count
            last_update = new_EnergyStateit∘(ψPlusPrev, ψhPos_in, current_step,last_update)
            update_state!( new_EnergyState ,ψPlusPrev ,ψhPos_in)
        end
        push!(update_steps,last_update)

```

in this case the output for update\_steps is

```julia
50-element Vector{Any}:
 new_EnergyStateit ∘ (CellState(), OperationCellField(), 1, 1.0)
 new_EnergyStateit ∘ (CellState(), OperationCellField(), 2, new_EnergyStateit ∘ (CellState(), OperationCellField(), 2, new_EnergyStateit ∘ (CellState(), OperationCellField(), 2, new_EnergyStateit ∘ (CellState(), OperationCellField(), 2, new_EnergyStateit ∘ (CellState(), OperationCellField(), 1, 1.0))))) 
.
.
.

```

---

<div class="post-metadata">

**Author:** ![gdalle](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/gdalle/32/27854_2.png) [@gdalle](https://discourse.julialang.org/u/gdalle)\
**Post date:** [November 7, 2024, 10:17pm UTC](https://discourse.julialang.org/t/iteration-counter/122394/2 "2024-11-07T22:17:43Z")

</div>

Sorry your question is not very clear to me, can you rephrase and provide a complete runnable code (with all imports and definitions), along with a description of what it does not do correctly?

---

<div class="post-metadata">

**Author:** ![mary](https://sea2.discourse-cdn.com/julialang/user_avatar/discourse.julialang.org/mary/32/53139_2.png) [@mary](https://discourse.julialang.org/u/mary)\
**Post date:** [November 7, 2024, 10:34pm UTC](https://discourse.julialang.org/t/iteration-counter/122394/3 "2024-11-07T22:34:05Z")

</div>

Sorry about that. let me clarify. I have applied incremental loading so there is n load steps which i have it in the code as count. at each count there is an if condition whether the energy is higher than previous load step or not. if it is true I should save that count and if it is not i should save the latest value of count. for example if I have 50 load steps I should have an array including 50 load steps and in each element I should have the count number if it satisfied the if condition or the latest one if it is not satisfied. this value should be save for each element of domain. I couldnt simplify the code more than this to be runnable.  
let me know if you have any questions.  
thank you

---

<div class="post-metadata">

**Author:** ![eldee](https://avatars.discourse-cdn.com/v4/letter/e/b5a626/32.png) [@eldee](https://discourse.julialang.org/u/eldee)\
**Post date:** [November 8, 2024, 5:56pm UTC](https://discourse.julialang.org/t/iteration-counter/122394/4 "2024-11-08T17:56:59Z")

</div>

> [@mary](#):
>
> Also I added this print lines to check the process but I couldnt get any print notifications out of it.

> [@mary](#):
>
> ```julia
> 50-element Vector{Any}:
> new_EnergyStateit ∘ (CellState(), OperationCellField(), 1, 1.0)
> 
> ```

While I also do not fully understand the question, I would assume the problem lies in

> [@mary](#):
>
> `last_update = new_EnergyStateit∘(ψPlusPrev, ψhPos_in, current_step,last_update)`

Here you are creating a `ComposedFunction` instead of calling `new_EnergyStateit`, so no print statements are reached. I assume you’d want to just use `last_update = new_EnergyStateit(ψPlusPrev, ψhPos_in, current_step, last_update)`. The same is probably also true in `ψhPos_in = (ψPos∘(ε(uh)))`.
