-1

I have assigned following values. Issue with this is that end1 and end2 values are not assigned when used inside the if statement. I have used string interpolation but still not assigned

My sample code is like this , three if conditions , one is like below

if(tp <="1.0")
 {   
   end1="nd"
   end2="ms"
 }


breakable {

for (row <- df.rdd.collect) {
var ts=row.mkString(",").split(",")(1)
var nd=row.mkString(",").split(",")(2)
var tp=row.mkString(",").split(",")(3)
var ms=row.mkString(",").split(",")(4)

    println(end1)  // this prints nd
    println(end2) // this prints ms

  // but in if statement end1 and end2 values doesn't assign with nd and ms 
   - neither it shows any error nor assigning the values

 if( end1 <="0.5" || end2 <="0.5")
   endtime=ts
   println("end timestamp is" + endtime)
   break()
   }
 }

I want the above if statement to be execute like

if( nd <="0.5" || ms <="0.5")  
// end1 and end2 changes as per the condition

but here the value is not assigned and do go inside the if statement.

zero323
  • 322,348
  • 103
  • 959
  • 935
stackoverflow
  • 59
  • 1
  • 1
  • 11

1 Answers1

0

I suppose the values are just being assigned inside the if and the reference is just lost for them when its going outside so i suggest you to initialize the variables first and then pass them where ever you want so that the reference is neither lost and the values will be updated each and every time where there is an update.

Sundeep Pidugu
  • 2,377
  • 2
  • 21
  • 43