float x;
for (int i = 0; i < length; i++){
float y;
// some logic that assigns a value to y
if (!x){ // <-- This throws an error ("if x doesn't exist yet")
x = y
} else if ( y < x){
x = y
}
}
Here I'm trying to find the smallest value of y returned inside the loop. The first time through the loop I want to assign the value of y found to x, and then on successive iterations only assign y to x if y is lower than the current x.
In other words I want to do something specific the first time through the loop (“if x doesn't exist yet”). However, it seems I can't check to see if x has been initialised.
Is there a way to do this or do I have to initialise x outside the loop to some unlikely huge value and hope the logic doesn't happen to generate a number for y greater than or equal to that value?