problems with consecutive if statements

I made a function that checks over several conditions tu return a string. the function is called when a navigation link is pressed the issue I'm having is that it breaks after the third if statement and only keeps checking after pressing the navigation link for the second time.

func diag() {
      viewModel.npH = Double(Float(viewModel.pH) ?? 0)
      viewModel.npCO2 = Double(Float(viewModel.pCO2) ?? 0)
      viewModel.nHCO3 = Double(Float(viewModel.HCO3) ?? 0)
      if viewModel.npH > 7.45 {
        diagnos.resultado1 = "alcalemia"
        print ("1")
        }
      if viewModel.npCO2 < 40 {
        diagnos.resultado2 = "alcalosis respiratoria"
        print ("2")
        }
      if viewModel.nHCO3 > 24 {
        diagnos.resultado3 = "alcalosis metabólica"
        print ("3")
      }
       
      if viewModel.npH < 7.35 {
        diagnos.resultado1 = "acidemia"
        print ("4")
      }
      if viewModel.npCO2 > 40 {
        diagnos.resultado2 = "acidosis respiratoria"
        print ("5")
      }
      if viewModel.nHCO3 < 24 {
        diagnos.resultado3 = "acidosis metabólica"
        print ("6")
      }
      if diagnos.resultado1 == "acidemia" && diagnos.resultado3 == "acidosis metabólica" && (viewModel.expectPCO2aci - 2)...(viewModel.expectPCO2aci + 2) ~= viewModel.npCO2 {
        diagnos.resultado4 = "acidosis metabólica compensada"
        diagnos.resultado2 = ""
        print ("7")
        }
      if diagnos.resultado1 == "alcalemia" && diagnos.resultado3 == "alcalosis metabólica" && (viewModel.expectALCPCO2 - 0.5)...(viewModel.expectALCPCO2 + 0.5) ~= viewModel.npCO2 {
        diagnos.resultado4 = "alcalosis metabólica compensada"
        diagnos.resultado3 = ""
        print ("8")
      }
      if diagnos.resultado1 == "alcalemia" && diagnos.resultado2 == "alcalosis respiratoria"
        && viewModel.agucro == 1
        && (viewModel.expectHCO3alkA - 0.5)...(viewModel.expectHCO3alkA + 0.5) ~= viewModel.nHCO3 {
        diagnos.resultado4 = "alcalosis respiratoria compensada"
        diagnos.resultado3 = ""
        print ("9")
      }
       
    }
  
}

this is the navigation link

NavigationLink("", isActive: $isShowingResultView) { ResultView() }

        Button("alteracion"){
          diag()
          calcular()
          isShowingResultView = true

        }

Could you describe a use case ?

You type:

  • viewModel.npH =
  • viewModel.npCO2 =
  • viewModel.nHCO3 =

You press button What prints do you get ?

Do you change values before new button tap ? What do you get in log ?

as you said, on my first screen I enter this three values viewModel.npH = viewModel.npCO2 = viewModel.nHCO3 =

when I first press the button It navigates to the second screen and prints 1 2 6 and it stops I back up to my first screen and when I press it again, it correctly checks all the conditional and prints 1 2 6 9

here is the print i get

problems with consecutive if statements
 
 
Q