How can I reset a function (boolean), like ON and OFF?

I have a boolean calles isgrounded, what I want to do in the function is to reset it, so that it turns true or false, if (hitInfo.distance < 0.5f)or (hitInfo.distance > 0.5f).

Somehow it is not working, but the raycasting works fine, I just dont know how to reset it. Because the order of the code only reads the last condition (if) and assumes it is true or false, but never resets it.

This is my function:

void IsGrounded()
{

    RaycastHit hitInfo;
    if (Physics.Raycast(rb.transform.position + Vector3.down * 1f, Vector3.up * 5f, out hitInfo, Mathf.Infinity))
    {

        if (hitInfo.distance > 0.5f) // Change .1f to what you need
            Debug.DrawRay(rb.transform.position + Vector3.down * 1f, Vector3.up * 5f, Color.blue);
        
        isgrounded = false;

        if (hitInfo.distance < 0.5f)
            Debug.DrawRay(rb.transform.position + Vector3.down * 1f, Vector3.up * 5f, Color.red);

        isgrounded = true;
    } 
 }

Add braces to move the assignments inside the if-statements:

if (Physics.Raycast(rb.transform.position + Vector3.down * 1f, Vector3.up * 5f, out hitInfo, Mathf.Infinity)) {

    if (hitInfo.distance > 0.5f) { // Change .1f to what you need
        Debug.DrawRay(rb.transform.position + Vector3.down * 1f, Vector3.up * 5f, Color.blue);

        isgrounded = false;
    }


    if (hitInfo.distance < 0.5f) {
        Debug.DrawRay(rb.transform.position + Vector3.down * 1f, Vector3.up * 5f, Color.red);

        isgrounded = true;
    }
}

You should also do some more coding tutorials, this is rather basic.