How do I make this animation play once on button press. Not loop.

using System.Collections;
using System.Collections.Generic;
using UnityEngine;

public class Hit : MonoBehaviour {

public float rotSpeed = 10f
;

public float rotBack = -10f;

public Vector3 startPoint;

public Animator anim;

// Use this for initialization
void Start()
{
    anim = GetComponent<Animator>();

}


// Update is called once per frame
void Update () {

    if (Input.GetKey("w"))
    {
        
        anim.Play("Attack");            

    }
  

}

}

One way to do this have a default idle animation for your object, then going into the Animator window, set the idle animation to default so it will be looping and make a transition arrow from the other animation towards the idle one. This way it will play once and go back to idle.