nums.size() vs int n = nums.size() in a For Loop: Which One Should You Actually Use?

You write this loop a hundred times a week and never think about it: for ( int i = 0 ; i < nums . size (); i ++ ) { } It compiles. It passes your tests. It ships. Then, months later — or thirty seconds into a coding interview — someone feeds it an empty vector, and everything goes sideways. Not a crash you can point to on line 12. Just... your loop runs forever, or reads garbage memory, or returns…